How to reuse intents in Android

2019-09-01 16:31发布

Hello All: I am creating an application in which I am using menus on every screen for the user to navigate. In my application, I have Screen1--> comes as home screen when the user logs in Screen2--> user goes to this screen to perform some operations. Now on Screen2 I want to have menu option to let the user go to home screen. But to start the activity we do

startActivity(new Intent(Home.this, Screen2.class));

But, I want to use the existing home screen which was created when the used logged in and then using onresume method I can update the home screen.

Can anybody please tell me how to use the existing intents or activity to provide menu options? Thanks Ashwani

2条回答
成全新的幸福
2楼-- · 2019-09-01 16:49

Take a look at android:launchMode attribute of element. Is "singleTop" launch mode is what you mean by "use existing home screen"? If you use "singleTop" the activity is not recreated, but receives onNewIntent() signal.

查看更多
我命由我不由天
3楼-- · 2019-09-01 17:11

Ashwani,

I believe this can be done with a setFlags() call on your Intent using the FLAG_ACTIVITY_REORDER_TO_FRONT flag. If screen 1 still exists it will bring it to the foreground. The documentation doesn't seem to specify, but I assume it launches a new Activity of Screen 1 was killed.

查看更多
登录 后发表回答