Is this the correct use of the constants into the onStartCommand() method?

17 views Asked by At

This is the method inside my AbstractService class.

@Override
    public int onStartCommand (Intent intent, int flags, int startId) {
        if(intent==null)
            return START_STICKY;
        String action = intent.getAction();
        if (action != null) {

            if (action.equals(getString(R.string.stop_foreground_action))) {
                stopForeground(true);
                stopSelf();
                return START_NOT_STICKY;
            }
            else if(action.equals(getString(R.string.test_action1))){
                //do stuff
            }
            else if(action.equals(getString(R.string.test_action2))) {
                //do studd
            }
        }
        return START_REDELIVER_INTENT;
    }

I basically say that if intent it's null, then it can create new instances of services without passing the last intent (START_STICKY). If the intent is not null and there is an action different from STOP, then it should pass the last intent in case the service is killed and then restarted (START_REDELIVER_INTENT). if the intent action is STOP, then it should not restart the service when is killed (START_NOT_STICKY).

And this is the method inside my ActualService that extends Abstract Service:

@Override
public int onStartCommand(Intent intent, int flags, int startId) {

        if (mOverlayView == null)
                buildView();

        return super.onStartCommand(intent, flags, startId);
    }

Which basically check if the overlayView is null, it builds the view and then right after call the onStartCommand() declared into the abstract class.

So, is this the correct use of constants?

0

There are 0 answers