0

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

Till
  • 682
  • 1
  • 6
  • 19
  • Sorry, but I didn't get your question, do you want to display the prompt when the app is brought to the foreground or exit the app when home is pressed ? – Salil Apr 08 '11 at 11:14
  • @Salil The main goal is to display the promt whenever the app is brought to foreground. One of my possible solutions is to exit the app, when home is pressed (i think) Thanks, Till – Till Apr 08 '11 at 11:18
  • you can override the onResume() in your activity and display the prompt there as its called when the app comes to foreground. – Salil Apr 08 '11 at 11:36
  • @Salil Yeah, but this will show the prompt even if I resume from another activity or if the activity is just started. That's far too often. – Till Apr 08 '11 at 12:00

2 Answers2

3

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

pankajagarwal
  • 13,462
  • 14
  • 54
  • 65
0

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

Manikandan
  • 4,358
  • 5
  • 19
  • 13
  • This will only kill the top activity on my activitystack, right? So if the activitystack is like -StartActivity --MyAct1 ---MyAct2 And in myact2 i call finish() only myact2 is finished and the startactivity is not resumed, right? – Till Apr 08 '11 at 10:51