如何退出的退出按钮Android应用程序? [英] how to exit android application from exit button?

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

问题描述

  

可能重复:
  机器人 - 出境申请code

我发现了一种退出的Andr​​oid应用程序的主屏幕(android手机)。

我的code未完全退出应用程序,但它把应用程序的根系活力。

这是我的code

  //防爆pression
    按钮退出=(按钮)findViewById(R.id.exit);
    exit.setOnClickListener(新OnClickListener()
    {
        @覆盖
        公共无效的onClick(视图v)
        {
            // TODO自动生成方法存根
            完();
            System.exit(0);
        }
    });
 

你能告诉我怎么退出应用程序并进入Android手机的主屏幕?

问候,

解决方案

 公共无效AppExit()
{

    this.finish();
    意向意图=新的意图(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_HOME);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(意向);

    / * INT PID = android.os.Process.myPid(); =====>如果你想杀死你的活动使用。但它并不是一个好做的。
    android.os.Process.killProcess(PID); * /

}
 

调用这个方法,你点击退出按钮

Possible Duplicate:
android - exit application code

I am finding the way to exit android application to home screen(android phone).

My code is not completely exit application but it turn to the root activity of application.

Here is my code

//Expression
    Button exit = (Button) findViewById(R.id.exit);
    exit.setOnClickListener(new OnClickListener()
    {
        @Override
        public void onClick(View v)
        {
            // TODO Auto-generated method stub
            finish();
            System.exit(0);
        }
    });

Can you tell me how to exit application and go to home screen of android phone?

Regards,

解决方案

public void AppExit()
{

    this.finish();
    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_HOME);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(intent);

    /*int pid = android.os.Process.myPid();=====> use this if you want to kill your activity. But its not a good one to do.
    android.os.Process.killProcess(pid);*/

}

call this method where you click exit button

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

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