Android How to Exit our application when Exit button click
When User click "Exit" button, Its go to device home screen.Then again click/select my applicat开发者_StackOverflowion its go to last opened activity.I houldn't go there.It need to go initial screen.How we can implement this.I have done using :
public void onExitAction(View botton){
SharedPreferences myPrefs = this.getSharedPreferences("myLogedPrefs",MODE_WORLD_READABLE);
myPrefs.edit().remove("myLogedPrefs");
myPrefs.edit().clear();
myPrefs.edit().commit();
Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(startMain);
finish();
}
Please help me..
Thanks in advance
Android applications don't have "exit" buttons. If you look at all of the applications that are part of the platform, none of them have exit buttons or menus.
If you want the user to return to the root activity of your app each time they launch it from its icon in the launcher, use this in your manifest:
http://developer.android.com/guide/topics/manifest/activity-element.html#clear
public void quit() {
int pid = android.os.Process.myPid();
android.os.Process.killProcess(pid);
System.exit(0);
}
and on exit button just call this method
btnExit.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
try {
quit();
} catch (Exception e) {
}
}
});
精彩评论