Rahul Kulhalli
Rahul Kulhalli

Reputation: 565

IntentService within an IntentService. Will it work?

I'm a beginner in Android programming, and I was just reading up on IntentServices. I have a doubt - If I issue a call to another class extending IntentService from within a class extending IntentService, will the call be valid?

As an overview, something like this -

public class MyIntentService extends IntentService{
    @Override
    public void onHandleIntent(Intent intent){
        //do stuff with incoming intent
        Intent newIntent = new Intent(getApplicationContext(), ABC.class);
        //ABC.class is another class extending IntentService
        startService(newIntent);
    }
}

Will this work?

Upvotes: 0

Views: 586

Answers (1)

Francesc
Francesc

Reputation: 29260

You can start activities from an Intent Service, but you need to add the NEW_TASK flag to it.

intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

You can also start another IntentService from an IntentService.

Upvotes: 3

Related Questions