Reputation: 1142
In my application,it requires to start the application from the starting activity or the first activity;as the application is authenticated by a login section..
So,whenever the application gets exit;say,via pressing BACK or HOME button,i need to start the application from the login itself...Is there any method to do the same?
I tried a simple technique by overriding the KEYEVENT,and implementing the finish() method inside.It works for the the BACK button;but its not working for the HOME button...
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_HOME) {
finish();
}
if (keyCode == KeyEvent.KEYCODE_BACK) {
finish();
}
return false;
}
Upvotes: 0
Views: 159
Reputation: 1142
Ya got the answer...
I just included the following attribute for the first activity to be displayed all the time,as i said in my question...
android:launchMode="singleTask"
android:clearTaskOnLaunch="true"
also include this attribute for the other activities...
android:finishOnTaskLaunch="true"
Just try......
Upvotes: 0
Reputation: 132982
when HOME Key Pressed onStop
is called so you can add finish();
in onStop()
for destory Activity and you can try to use onUserLeaveHint()
this method also called when user press Home key
Upvotes: 1
Reputation: 6071
If I'm not mistaken, one can not override the HOME-button, as it should enable the user to back out of an app at any given point.
Upvotes: 1
Reputation: 3436
take a look at this:
basically, everytime your application gets paused, you close the activity so it has to be restarted again. You can do this by overriding the onPause method and closing the activity there
Upvotes: 4