如何彻底关闭Android应用程序 [英] how to close android app completely

查看:353
本文介绍了如何彻底关闭Android应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个注销选项的Andr​​oid应用程序在 onCreateOptionsMenu 。在注销完美的作品,但是当我preSS后退按钮再需要我的previous活动,而当它得到一个空值重定向到登录界面。现在我的登录屏幕频频出现。我要彻底关闭应用程序,当我preSS后退按钮,但不知道怎么办。

I created an android application with a logout option in onCreateOptionsMenu. The Logout works perfectly but when I press the back button again it takes me to the previous activity, and when it gets a null value it redirects to login screen. Now my login screen appears again and again. I want to close the app completely when I press the back button but don't know how.

下面是我的code来处理后退按钮preSS在登录屏幕:

Here is my code to handle the back button press in the login screen:

@Override
public void onBackPressed() {
    new AlertDialog.Builder(this)
        .setTitle("BidNEMO")
        .setMessage("Are you sure you want to exit?")
        .setNegativeButton(android.R.string.no, null)
        .setPositiveButton(android.R.string.yes, new OnClickListener() {
         public void onClick(DialogInterface arg0, int arg1) {
         Main.super.onBackPressed();
         finish();
         }
         }).create().show();
     }

请帮忙guyss ..

please help guyss..

推荐答案

退出按钮上点击使用这个应用code:

To Quit Application on Button click use this code :

Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
startActivity(intent);

试试看。

要杀死完整的应用程序,并从删除它运行应用程序列表中杀掉通过 PID (其讨厌的应用程序)......之前使用上述code此行。

To kill the complete app and remove it from Runningapp list kill the app through its pid(its nasty)... use this lines before above code.

int pid = android.os.Process.myPid();
android.os.Process.killProcess(pid);

这篇关于如何彻底关闭Android应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆