如何在Android应用中使用带有FLAG_ACTIVITY_REORDER_TO_FRONT的putExtra()?

时间:2011-08-24 11:42:21

标签: android android-intent

我有一个应用程序,调用“App1”。在我的App1中,我调用了Camera应用程序。

intent = new Intent(Intent.ACTION_MAIN);
intent.setComponent(new ComponentName("com.android.camera","com.android.camera.Camera"));
startActivity(intent);

之后,我使用FileObserver来监听用户是否拍照。当发生这种情况时,我打电话给

Context ctx = App1.this.getApplicationContext();
Intent j = new Intent(ctx, App1.class);
j.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
j.putExtra("type", 1);
startActivity(j);

它有效,我的意思是它让我的应用程序在前面如何离开它,但是我需要传递一个称为“类型”的整数。我想,我的应用程序将调用“onResume()”但是如何获得额外的整数。这种类型的传递在我的应用程序中没有做任何事情。

在onCreate方法中有Bundle savedInstanceState,但在onResume方法中没有这样的东西。所以,我需要你的帮助来解决这个问题。提前谢谢。

1 个答案:

答案 0 :(得分:55)

您需要覆盖Activity.onNewIntent()方法。

@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);
    setIntent(intent);
}

调用onNewIntent()后,将遵循正常的onResume()生命周期。或者,您可以在onNewIntent()本身编写代码。