optimizely/android-sdk

Disable schedule

wilek opened this issue · 3 comments

wilek commented

Disabling sync not working when previously was enabled (interval > 0). When sync interval is disabled, then previously scheduled service intent are starting.
Previously scheduled intents schould be removed when interval is <= 0.

public void schedule(Intent intent, long interval) {
        if (isScheduled(intent)) {
            unschedule(intent);
        }

        if (interval < 1) {
            logger.error("Tried to schedule an interval less than 1");
            return;
        }

        PendingIntent pendingIntent = pendingIntentFactory.getPendingIntent(intent);

        setRepeating(interval, pendingIntent, intent);

        logger.info("Scheduled {}", intent.getComponent().toShortString());
    }

@wilek are you saying that unschedule is not being called? As a work around for now, can you call unschedule yourself? Can you tell me what version you are seeing this in (i.e. Android O API 26 and greater)? Reoccurring events are canceled. However, there is a chance that an intent could be serviced after it is unscheduled. But, it should not reoccur.

actually, the preferred way of stopping a scheduled datafile handler intent is by calling stopBackgroundUpdates.
optimizelyManager.getDatafileHandler().stopBackgroundUpdates(myApplication, MyApplication.PROJECT_ID);
If there is no background process, it shouldn't have any effect.

I now understand that this is a suggestion on allowing stopping scheduled jobs by passing in -1 or 0. I will look into it. @wilek Thank you for the suggestion! :)

This issue has been fixed in #397