退出Android应用程序编程 [英] exit android application programmatically

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

问题描述

我有两个活动,首先是一个醒目的活动。 我想知道如何退出该应用程序的第二个活动主页。 我用这个方法,它的工作原理,但它需要的启动器。

 公共无效AppExit()
{

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


}
 

解决方案

每当你想退出所有打开的活动,你应该preSS一个按钮,加载运行的第一个活动,当你的应用程序启动,然后清除所有其他活动,然后让剩余的最后一个活动完成。这样做可以应用下面的code在乌拉圭回合项目

 意向意图=新的意图(getApplicationContext(),FirstActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra(EXIT,真正的);
startActivity(意向);
 

以上code完成除FirstActivity所有活动。然后,我们需要完成FirstActivity在输入低于code Firstactivity的OnCreate

 如果(getIntent()getExtras()= NULL和放大器;!&安培; getIntent()getExtras()getBoolean(EXIT,FALSE)){
    完();
}
 

和你做......

完成所有活动的时间

I have two activities, the first is a splash activity. I would like to know how to exit the application from the second activity to the homepage. I've used this method it works BUT it takes to the launcher.

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


}

解决方案

Whenever you wish to exit all open activities, you should press a button which loads the first Activity that runs when your application starts then clear all the other activities, then have the last remaining activity finish. to do so apply the following code in ur project

Intent intent = new Intent(getApplicationContext(), FirstActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra("EXIT", true);
startActivity(intent);

The above code finishes all the activities except for FirstActivity. Then we need to finish the FirstActivity's Enter the below code in Firstactivity's oncreate

if (getIntent().getExtras() != null && getIntent().getExtras().getBoolean("EXIT", false)) {
    finish();
}

and you are done....

From Finish all activities at a time

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

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