سؤال

I have three activities, lets call them Act1, Act2 and Act3. There is a login form on Act1 which (upon successful login) goes to Act2 which has two options (1. Go to Act3, Go to Act3 with some extra data). The user then goes to Act3.

Of course, when the user presses the "home" button the android device, the application is minimized and held in memory until android needs to use the memory (in which case the App is destroyed). However, when the user presses the "home" button and then opens the app up again quickly, the app is restored to the Activity that was in the foreground before it was minimized.

I want to be able to minimize the app, and then once re-opened go straight to Act1 to prompt the user to login again. I do not want the app to be able to resume in Act2 or Act3.

هل كانت مفيدة؟

المحلول

Unless your application is really security-sensitive, the default behavior should be better for the user: typing their login and password every single time they launch the app can be very annoying. Take for example the native GMail application: it doesn't require you to reauthenticate every time it opens.

Now, if your application really needs that behavior (say it's a credit card safe or something like that), then my first guess would be to handle Act3's onPause() and call finish() from there. Just be careful not to call finish() twice (see isFinishing()).

Also, since this is a breakage of the user's expectations, make it clear to the user that your app behaves like that for their security, not because it wants to be annoying.

نصائح أخرى

When the user moves away from your activity (pressing the home button for example), the onPause() method is called first. You should be able to handle your logic there (for example, calling finish() on Act2 or Act3).

Edit: heh, yeah, what he said :D

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top