How to use putExtra() with FLAG_ACTIVITY_REORDER_TO_FRONT in Android Apps?

可紊 提交于 2020-01-01 01:52:32

问题


I have an application, call "App1". In my App1 I invoke Camera application.

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

After that, I use FileObserver to listen whether user take a photo. When this happens I call

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

It works, I mean it gets my application to front how I leave it, however I need to pass an integer, which is called "type". I think, my application will call "onResume()" but how can I get that extra integer. This type of passing didn't do anything in my application.

There's Bundle savedInstanceState in onCreate method, but there is no such a thing in onResume method. So, I need your help to solve this problem. Thanks in advance.


回答1:


You need to override Activity.onNewIntent() method.

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

After onNewIntent() is called, the normal onResume() lifecycle will follow. Alternatively, you can write your code in onNewIntent() itself.



来源:https://stackoverflow.com/questions/7174832/how-to-use-putextra-with-flag-activity-reorder-to-front-in-android-apps

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!