danizmax
danizmax

Reputation: 2456

I get "Unknown service start result" error on multiple intents

I'm trying to invoke certain functions of my service with intents sent from my activity.

This is how I send intents from activity (in UI thread):

Intent it = new Intent(MyService.INTENT_ACTIVITY_POSITION_CHANGED);
it.setClass(getApplicationContext(), MyService.class);
it.putExtra("posPercentX", x);
it.putExtra("posPercentY", y);
startService(it);

This is how my onStartCommand looks like in MyService:

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

       if(intent.getAction().equals(INTENT_ACTIVITY_START)){
        Toast.makeText(this,"onStartCommand ...", Toast.LENGTH_SHORT).show();
       }else if(intent.getAction().equals(INTENT_ACTIVITY_POSITION_CHANGED)){
        // here comes some code to get extras from intent
        Log.d("INTENT_ACTIVITY_POSITION_CHANGED", "x=" + posX + " y=" + posY);
        //TODO preveri
       }
       return startId;
    }

after few calls I get:

ERROR/ActivityManager(52): java.lang.IllegalArgumentException: Unknown service start result: 4

Why do I get this error? any idea?

Upvotes: 0

Views: 1151

Answers (1)

Falmarri
Falmarri

Reputation: 48577

Why do you think you should be returning startId? The documentation for onStartCommand() is

intent The Intent supplied to startService(Intent), as given. This may be null if the service is being restarted after its process has gone away, and it had previously returned anything except START_STICKY_COMPATIBILITY.

flags Additional data about this start request. Currently either 0, START_FLAG_REDELIVERY, or START_FLAG_RETRY.

startId A unique integer representing this specific request to start. Use with stopSelfResult(int). Returns

* The return value indicates what semantics the system should use for

the service's current started state. It may be one of the constants associated with the START_CONTINUATION_MASK bits

So you need to return START_STICKY, or one of the values from http://developer.android.com/reference/android/app/Service.html#START_CONTINUATION_MASK

Upvotes: 5

Related Questions