My tests
Calling StartActvity(SecondActivity) from a Service, directly without flags (
Android 5)
- if Main is running -> Shows SecondActivity in front of it (OK)
- if Main is paused -> Redraws Main and shows second Activity in front of it (NOT OK)
- if Main is Finished -> Shows SecondActivity in front of whatever is running (OK)
Calling StartActivity(SecondActivity) from a Service, with an intent with flags (
Android 5)
- if Main is running -> Shows SecondActivity in front of it (OK)
- if Main is paused -> Shows SecondActivity in front of whatever is running (OK)
- if Main is Finished -> Shows SecondActivity in front of whatever is running (OK)
Calling StartActivity(SecondActivity) from a service, directly without flags (
Android 4.)
- if Main is running -> Shows SecondActivity in front of it (OK)
- if Main is paused -> Redraws Main and shows second Activity in front of it (NOT OK)
- if Main is Finished -> Shows SecondActivity in front of whatever is running (OK)
Calling StartActivity(SecondActivity) from a Service, with an intent with flags (
Android4)
- if Main is running -> SecondActivity never appears (NOT OK)
- if Main is paused -> Main is Resumed, but NOT SecondActivity (NOT OK)
- if Main is Finished -> Shows SecondActivity in front of whatever is running (OK)
So, it seems that:
* Calling StartActivity() wth no flags in this case seems to have consistent behaviour in both 4.X and 5 Android versions. The drawback is that when main activity is Paused, in both cases Main Actvity is drawn under the SecondActivity before it is called.
* Best approach seems to detect if Android 5 is running and call StartActivity with an intent. If Android 4, try to finish the Activity if it is Paused.
* Not even sure that these result can be valid for other cases, just a little bit lost
To solve this, I would need to solve some of these points
-A magical flag combination which always works
-Knowing how Android treats the stack of activities and priorities when they are launched from a service
-Know wether a given paused activity is just paused or has been killed/finished
-Be able to kill externally an activity (similar to Activity.Finish but from a Service)