Android如何在退出按钮单击时退出我们的应用程序

时间:2011-08-24 06:59:00

标签: android

当用户点击“退出”按钮时,它进入设备主屏幕。然后再次点击/选择我的应用程序,进入上次打开的活动。我不能去那里。需要进入初始屏幕。我们如何实施我已经完成了使用:

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();      
}

请帮帮我..

提前致谢

2 个答案:

答案 0 :(得分:1)

Android应用程序没有“退出”按钮。如果您查看作为平台一部分的所有应用程序,它们都没有退出按钮或菜单。

如果您希望用户每次从启动器中的图标启动应用时返回应用的根活动,请在清单中使用此活动:

http://developer.android.com/guide/topics/manifest/activity-element.html#clear

答案 1 :(得分:-2)

public void quit() {
        int pid = android.os.Process.myPid();
        android.os.Process.killProcess(pid);
        System.exit(0);
    }

然后在退出按钮上调用此方法

btnExit.setOnClickListener(new View.OnClickListener() {
                    public void onClick(View arg0) {
                        try {
                        quit(); 
                        } catch (Exception e) {

                        }
                    }
                });
相关问题