Launcher + singleTask activity in Android

I have a problem starting activity in my project.

The activity "My" (H) allows you to select some kind of service in it. Suppose S11 → ...-> S1n is the activity flow for the service (S1). H - LAUNCHER action for my application.

In addition, I need to switch to another application from H and vice versa. Since I cannot change the behavior of this application, I have to declare my H activity as "singleTask" to prevent multiple instances in my activity stack.

The problem is that my application cannot be overwritten without shortening the actions that were transferred after H. So for example, if I have H-S11-S12, then press HOME and restart from the menu of recent applications. I get H as the foreground.

Any ideas? Is there any way to make this combination work? Thanks!

+6
source share
1 answer

You do not 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); } ... } 
-1
source

Source: https://habr.com/ru/post/908496/


All Articles