强制退出Android应用使用System.exit(0)不起作用 [英] Force quit of Android App using System.exit(0) doesn't work

查看:1976
本文介绍了强制退出Android应用使用System.exit(0)不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我试图通过覆盖功能,Android设备的后退按钮和System.exit(0),这不起作用退出我的Andr​​oid应用程序。

when I try to quit my Android application by overwriting the function for the back-button of Android devices and "System.exit(0)", this doesn't work.

我有一个活动叫LoginActivity和一个活动名为OverviewActivity。

I have an activity named "LoginActivity" and an activity named "OverviewActivity".

当我开始在OverviewActivity意图切换到LoginActivity,这个工作。

When I start an intent in OverviewActivity to switch to LoginActivity, this works.

Intent changeViewIntent = new Intent(OverviewActivity.this,
            LoginActivity.class);
startActivity(changeViewIntent);

现在我在LoginActivity并没有被覆盖的方法:

Now I am in LoginActivity and there is the overwritten method:

@Override
public void onBackPressed() {
    System.exit(0);
}

但是,当我preSS背键(例如,在设备模拟器)屏幕是空白了一毫秒,然后又回到了OverviewActivity。

But when I press the back-key (e.g. in the device simulator) the screen is blank for a millisecond and then it goes back to the OverviewActivity.

这是怎么回事?我只是想强制关闭时,背关键是pressed。

Why is this happening? I just want to force the close when the back-key is pressed.

历史禁用在清单中的OverviewActivity没有选择,因为有几种方法可以从其他活动访问OverviewActivity。

History disabling for the OverviewActivity in the manifest is no option, because there are several ways to access the OverviewActivity from other activities.

也许有一个想法?安卓4.0是minimium要求,因此它没有工作在较低的版本。

Maybe there is an idea? Android 4 is minimium requirement, so it doesn't have to work on lower versions..

谢谢!

推荐答案

该退出删除整个活动的呼叫历史并启动家庭Scrren的家庭活动是可能的。

The Exit is possible by deleting the whole activity-call-history and starting the Home-Activity of the Home-Scrren.

Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);

这篇关于强制退出Android应用使用System.exit(0)不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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