开发者

How To Reuse Activity on Top of Stack

My app has a single entry activity called "Main". In "Main" I call one of three other activities A, B, or C (based on a preference) and then immed开发者_如何学Goiately exit/finish "Main" so that only A, B, or C are active.

I also have a permanent notification in the notification bar that users can pull down (at any time) to conveniently restart my App (calls intent with "Main" component).

The problem is that if my app is already running and users pull down the notification and restart, I get A or B or C running on top of the previous activity (also A, or B, or C). How can I avoid this (i.e. reuse the activity on top of the stack)?

I've tried Intent.FLAG_ACTIVITY_* and nothing seems to work. I've tried launchModes

in the Manifest and it also didn't seem to work. Any ideas? Any help appreciated....jh


I found a way to do this that does what I want (though I'm still testing it)...

In the Android Manifest, for activities A, B, and C, I added the following line:

android:launchMode="singleTask"

This had the result of reusing activities A, B, or C if they were already at the top of the stack so that they wouldn't be restarted on top of themselves (which was requiring hitting the BACK button twice to exit the task).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜