开发者

Reorder Android task to front

开发者 https://www.devze.com 2023-04-02 18:01 出处:网络
I have a problem : My application has several activities ( e.g. StartActivity, MainActivity ), and a service ( e.g. MainService ).

I have a problem :

My application has several activities ( e.g. StartActivity, MainActivity ), and a service ( e.g. MainService ).

When the user tap the Home button, the activity becomes no longer visible, but the service is still running ( normal workflow ).

What I have to do now is that when my serv开发者_如何学Cice receives a particular Broadcast, I want bring to foreground the MainActivity - the existing instance - ( it is not the activity that has the intent-filter android.intent.action.MAIN ).

I tried that solution, but it only works with the flag : Intent.FLAG_ACTIVITY_NEW_TASK, and I can't use this flag because I don't want to start a new task, I just want to bring the existing to front ( and consequently avoid multiple instances of the app ).

Thanks a lot.

Regards.


You need to add the flag FLAG_ACTIVITY_NEW_TASK if you are starting the activity from the service.

To multiple instance you can add this to your activity tag in your manifest file:

android:launchMode = "SingleTask"
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号