I have two activities, one is MainActivity (the launch activity), the other is MaskActivity. If I start my app from other app, and start MaskActivity from MainActivity (now MaskActivity is on top of MainActivity), problem arises when I press home button on the phone and re-enter my app, a new MainActivity is started and put on top of the MaskActivity and the old MainActivity, which is not what I want.

But if I start my app from program list(not from other apps), things act quite right as I wanted, when re-enter my app, no new MainActivity is started and MaskActivity is on top of MainActivity.

My MainActivity's launchMode is "singleTop", I don't know if this is the problem. Simply change it to "singleInstance" or others can not fix the problem. When changed to "SingleInstance", it won't start a new MainActivity but will bring MainActivity to top. But I want the MaskActivity stay on top when the program resumed if the MaskActivity is on top of the MainActivity before the program paused.

Any ideas?

有帮助吗?

解决方案

What you're asking for is a little unusual. Usually apps that provide intent-filters have specific activities that can handle those intent filters. For example, if you have a image viewing application, the "image gallery" activity will handle the "view" intent-filter.

If I understand correctly, you're saying that both activities can handle the case where your app is launched from another activity? Perhaps your two activities are closely linked (in terms of functionality). Perhaps you should have just one Activity, and put the view content of the two Activities into Fragments. Those fragments can be hidden or shown within your Activity. Your Activity can be singleTask, and will always be showing the correct content when it is launched (as you want).

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top