Paul E.
Paul E.

Reputation: 2009

Launcher + singleTask activity in Android

I have a problem with activity launching in my project.

My 'Home' activity (H) allows to choose some service in it. Lets say S11->...-> S1n is an activity flow for the service (S1). H is the LAUNCHER activity for my app.

Also, i need to switch to another app from H and back to it. As I cannot change that app behaviour, i have to declare my H activity as 'singleTask' to prevent from having several instances of it in my activity stack.

The problem is that my app cannot be relaunched without cutting away the activities that had been pushed after H. So for example if I have H-S11-S12, then press HOME and relaunch from recent apps menu I get H as a foreground activity.

Any ideas? Is there any way to get this combination working? Thanks!

Upvotes: 7

Views: 591

Answers (1)

tiny sunlight
tiny sunlight

Reputation: 6251

You don't need singleTask. Use startActivityForResult instead of startActivity. Or use Fragments instead of Activities

startActivityForResult(new Intent(H.this,S11),1);

public onActivityResult(int requestCode ){
    if(requestCode == 1){
       startActivityForResult(new Intent(H.this,S12),2);
    }else if(requestCode == 2){
       startActivityForResult(new Intent(H.this,S12),3);
    }
    ...
}

Upvotes: -1

Related Questions