Android的出境申请 [英] Android exit application

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

问题描述

这不是建议退出应用程序直接,因此关键是要完成所有活动,使一切顺利的背景和用户返回到主屏幕。我的问题是我的主要活动,它总是用旗Intent.FLAG_ACTIVITY_CLEAR_TOP推出| Intent.FLAG_ACTIVITY_SINGLE_TOP它推出另一项活动,在这里我想将退出按钮。为了得到一切的背景我要完成当前和主要活动。我虽然是开展的主要活动与标志和额外的信息,它应该退出会做的伎俩,但交付的意图群众演员没有达到主要活动 - 它仍然获取用于由机器人来启动应用程序的意图

it's not recommended to exit application directly, so the point is to finish all activities so everything goes to the background and user returns to the home screen. My problem is that I have main activity, which is always launched with flags Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP and it launches another activity, where I want to place the exit button. In order to get everything to the background I have to finish both current and main activity. I though that launching main activity with those flags and extra info that it should exit would do the trick, but the extras delivered with the intent do not reach main activity - it still gets the intent that was used by android to launch the application.

换句话说,我想是这样的:

In other words, I tried something like:

// Exit's onClick:
Intent intent = new Intent(someContext, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.putExtra("exit", true);
context.startActivity(intent);
currentActivity.finish();

// MainActivity onCreate:
Bundle extras = getIntent().getExtras();
if (extras != null)
{
  // application never reach this point
  boolean exit = extras.getBoolean("exit");
  if (exit)
  {
    finish();
    return;
  }
}

临时演员交付。我怎样才能得到它的工作?

The extras are delivered. How can I get it working?

感谢

推荐答案

在此设置2标志MainActivity不会达到的onCreate(),如果它仍然是在堆栈中。这就需要onNewIntent()。

When setting this 2 flags MainActivity will not reach onCreate() if it is still in the stack. This would call onNewIntent().

检查这2详细信息的链接:

Check this 2 links for more information:

http://developer.android.com/reference/android/content/Intent.html#FLAG_ACTIVITY_CLEAR_TOP

<一个href="http://developer.android.com/reference/android/app/Activity.html#onNewIntent%28android.content.Intent%29" rel="nofollow">http://developer.android.com/reference/android/app/Activity.html#onNewIntent%28android.content.Intent%29

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

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