Resume after pressing 'Home' should start my Startactivity

爷,独闯天下 提交于 2020-01-03 04:54:34

问题


I want my app to have a password-query. This should be displayed every time the app is started or resumed.

So I have declared a Startactivity that shows a password prompt. If the user closes the App by pressing 'Back'-hardware Button some times everything is fine. But if the user pauses the app by pressing 'Home' the app opens in the activity displayed before without showing my prompt.

1)What is the best way to implement this as I want? Maybe doing something in OnStop() of each activity but this is called to often, not only when the app is closed by 'Home'.

2)Is there any other way to close the app so that my promt is not displayed? Where do I have to pay attention?

Thanks and best regards, Till


回答1:


If you want to clear your activity stack everytime the user brings the app to fore-ground after pressing the home key and the passowrd screen to top the set android:clearTaskOnLaunch="true" in the application tag in the manifest and set <category android:name="android.intent.category.LAUNCHER" /> for your Startactivity




回答2:


After pressing home button you have to finish() your activity.



来源:https://stackoverflow.com/questions/5593953/resume-after-pressing-home-should-start-my-startactivity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!