press home key button and reinitialize the application

My application activity is facing a scenario when user press Home button on android phone.

I have used OnPause() method . this i called when user press Home key. and Normal cicumstances when user launch the app again, it calls the onResume() method of the activity.

But sometimes, when user re-launch the application, it opens the Launcher Activity(instead of calling the current activity.)

So I am confused. in my phone it always calls the current activity. But sometime on another phone, i see that it calls the launcher activity and application starts again.

How to solve this issue? Am i doing something wrong?


Try android:launchMode="singleTop" .

As the doc says:

If an instance of the activity already exists at the top of the target task, the system routes the intent to that instance through a call to its onNewIntent() method, rather than creating a new instance of the activity.


按主页按钮意味着最小化应用程序。它不清楚堆栈,那么应用程序将启动onPause()和onStop()状态。当用户启动应用程序时,它会执行onResume()方法,因为应用程序实例已经创建。

链接地址: http://www.djcxy.com/p/26178.html

上一篇: 如何在android中保存应用程序状态

下一篇: 按Home键并重新初始化应用程序