Example usage for android.app Service START_FLAG_REDELIVERY

List of usage examples for android.app Service START_FLAG_REDELIVERY

Introduction

In this page you can find the example usage for android.app Service START_FLAG_REDELIVERY.

Prototype

int START_FLAG_REDELIVERY

To view the source code for android.app Service START_FLAG_REDELIVERY.

Click Source Link

Document

This flag is set in #onStartCommand if the Intent is a re-delivery of a previously delivered intent, because the service had previously returned #START_REDELIVER_INTENT but had been killed before calling #stopSelf(int) for that Intent.

Usage

From source file:com.olheingenieros.listexample.sync.TutListDownloaderService.java

@Override
public int onStartCommand(final Intent intent, final int flags, final int startID) {
    URL tutorialPath;/* w  w w . j  av  a2 s  .  c  o m*/
    try {
        tutorialPath = new URL(intent.getDataString());
        tutorialDownloader = new DownloaderTask();
        tutorialDownloader.execute(tutorialPath);
    } catch (final MalformedURLException e) {
        LOGE(TAG, "BAD URL", e);
    }
    return Service.START_FLAG_REDELIVERY;
}

From source file:com.shinymayhem.radiopresets.ServiceRadioPlayer.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    if (LOCAL_LOGV)
        log("onStartCommand()", "v");

    //check if resuming after close for memory, or other crash
    if ((flags & Service.START_FLAG_REDELIVERY) != 0) {
        //maybe handle this with dialog and tap to resume
        if (LOCAL_LOGD)
            log("Intent redelivery, restarting", "d");
    }/*from w  w  w  . j  ava  2 s.  co m*/

    mIntent = intent;
    if (intent == null) {
        if (LOCAL_LOGD)
            log("No intent", "w");
    } else {
        String action = intent.getAction();
        if (action == null) {
            if (LOCAL_LOGD)
                log("No action specified", "w"); //why?
            //return flag indicating no further action needed if service is stopped by system and later resumes
            return START_NOT_STICKY;
        } else if (action.equals(Intent.ACTION_RUN)) //called when service is being bound by player activity
        {
            if (LOCAL_LOGV)
                log("service being started probably so it can be bound", "v");
            return START_NOT_STICKY;
        } else if (action.equals(ACTION_PLAY.toString())) //Play intent
        {
            int preset = Integer.valueOf(intent.getIntExtra(ActivityMain.EXTRA_STATION_PRESET, 0));
            if (LOCAL_LOGD)
                log("PLAY action in intent. Preset in extra:" + String.valueOf(preset), "d");
            play(preset);
            //return START_REDELIVER_INTENT;
            return START_NOT_STICKY;
        } else if (action.equals(ACTION_PLAY_STREAM.toString())) //Play intent
        {
            if (LOCAL_LOGV)
                log("PLAY_STREAM action in intent", "v");
            String url = intent.getStringExtra(EXTRA_URL);
            if (LOCAL_LOGD)
                log("URL in extra:" + url, "d");
            //check whether the url should be updated (for metadata retrieval purposes)
            boolean updateUrl = intent.getBooleanExtra(EXTRA_UPDATE_URL, false);
            if (updateUrl) {
                mUrl = url;
            }
            playUrl(url);
            //return START_REDELIVER_INTENT;
            return START_NOT_STICKY;
        } else if (action.equals(ACTION_UNSUPPORTED_FORMAT_ERROR.toString())) {

            String format = intent.getStringExtra(EXTRA_FORMAT);
            if (LOCAL_LOGD)
                log("Known unsupported format: " + format, "d");
            String title = getResources().getString(R.string.error_title);
            String message = getResources().getString(R.string.error_format) + ":" + format;
            mCurrentPlayerState = ServiceRadioPlayer.STATE_ERROR;
            //set 'now playing' to error
            stopInfo(getResources().getString(R.string.status_error));
            this.getErrorNotification(title, message);
            return START_NOT_STICKY;
        } else if (action.equals(ACTION_FORMAT_ERROR.toString())) {
            String message = intent.getStringExtra(EXTRA_ERROR_MESSAGE);
            if (LOCAL_LOGD)
                log("URL was unable to play:" + message, "d");
            String title = getResources().getString(R.string.error_title);
            mCurrentPlayerState = ServiceRadioPlayer.STATE_ERROR;
            //set 'now playing' to error
            stopInfo(getResources().getString(R.string.status_error));
            this.getErrorNotification(title, message);
            return START_NOT_STICKY;
        } else if (action.equals(ACTION_STREAM_ERROR.toString())) {

            int responseCode = intent.getIntExtra(EXTRA_RESPONSE_CODE, 0);
            String responseMessage = intent.getStringExtra(EXTRA_RESPONSE_MESSAGE);
            if (LOCAL_LOGD)
                log("Stream error. Code:" + String.valueOf(responseCode) + ", Message:" + responseMessage, "d");
            String title = getResources().getString(R.string.error_title);
            String message;
            switch (responseCode) {
            case 404:
                message = getResources().getString(R.string.error_not_found);
                break;
            case 400:
                if (responseMessage.equals("Server Full")) {
                    message = getResources().getString(R.string.error_server_full);
                } else {
                    message = getResources().getString(R.string.error_unknown);
                }
                break;
            default:
                message = getResources().getString(R.string.error_unknown);
            }
            mCurrentPlayerState = ServiceRadioPlayer.STATE_ERROR;
            //set 'now playing' to error
            stopInfo(getResources().getString(R.string.status_error));
            this.getErrorNotification(title, message);
            return START_NOT_STICKY;
        } else if (action.equals(ACTION_NEXT.toString())) //Next preset intent
        {
            if (LOCAL_LOGD)
                log("NEXT action in intent", "d");
            nextPreset();
            return START_NOT_STICKY;
        } else if (action.equals(ACTION_PREVIOUS.toString())) //Previous preset intent
        {
            if (LOCAL_LOGD)
                log("PREVIOUS action in intent", "d");
            previousPreset();
            return START_NOT_STICKY;
        } else if (action.equals(ACTION_STOP.toString())) //Stop intent
        {
            if (LOCAL_LOGD)
                log("STOP action in intent", "d");
            end();
            return START_NOT_STICKY;
        } else if (action.equals(ACTION_LIKE.toString())) //Stop intent
        {
            if (intent.hasExtra(EXTRA_SET_TRUE)) {
                boolean set = intent.getBooleanExtra(EXTRA_SET_TRUE, false);
                if (set) {
                    if (LOCAL_LOGD)
                        log("LIKE action in intent with true", "d");
                    this.like();
                } else {
                    if (LOCAL_LOGD)
                        log("LIKE action in intent with false", "d");
                    this.unlike();
                }
            }

            return START_NOT_STICKY;
        } else if (action.equals(ACTION_DISLIKE.toString())) //Stop intent
        {
            if (intent.hasExtra(EXTRA_SET_TRUE)) {
                boolean set = intent.getBooleanExtra(EXTRA_SET_TRUE, true);
                if (set) {
                    if (LOCAL_LOGD)
                        log("DISLIKE action in intent with true", "d");
                    this.dislike();
                } else {
                    if (LOCAL_LOGD)
                        log("DISLIKE action in intent with false", "d");
                    this.undislike();
                }
            }
            return START_NOT_STICKY;
        } else if (action.equals(ACTION_PULL_WIDGET_INFO.toString())) {
            if (LOCAL_LOGV)
                log("UPDATE_WIDGET action in intent", "v");
            updateDetails();
            endIfNotNeeded();

            return START_NOT_STICKY;
        } else {
            log("Unknown Action:" + action, "w");
        }
    }

    //return START_STICKY;
    return START_NOT_STICKY;
    //return START_REDELIVER_INTENT;
}