tags:

views:

29

answers:

2

i am developing a password storage software. To enter into the application we have to login with valid details.

Now when i press home key, the application should log of automatically and then start all over again from security perspective. It should logout everytime the home key is pressed. How do i do it?

+1  A: 

You could try using onpause to logoff

Ravi Vyas
A: 

Listening for the home key to be pressed doesn't make much sense on Android since the user can leave your application by a lot of different ways.

What you can do instead is to override onStop() or onPause() depending on your paranoia level, and logout the user in this event.

You can find details on the lifecycle of an Activity in the official documentation : http://developer.android.com/guide/topics/fundamentals.html#actlife

I would suggest you to override these two methods with some debugging inside, try your application and decide in which you should put your logout() code.

@Override
public void onPause() {
     super.onPause();
     Log.d("MyTestActivity", "onPause()");
}

@Override
public void onStop() {
     super.onStop();
     Log.d("MyTestActivity", "onStop()");
}
Gautier Hayoun