Launcher + singleTask activity in Android
Asked Answered
S

1

7

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!

Sporogonium answered 15/2, 2012 at 9:30 Comment(3)
can you explain it with better examples, what do you mean by need to switch to another app from H and back to it, and activities S11.... ?Retaliation
so the problem is that when you re-open app from recent app list, other activities in the stack should remain in stack, right?Anywise
How do you start "the other app"? I cannot see how it causes multiple instances of your H activity.Enjoy
G
-1

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);
    }
    ...
}
Gravitt answered 11/4, 2016 at 15:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.