How to reuse intents in Android

℡╲_俬逩灬. 提交于 2020-01-06 05:49:05

问题


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


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/6129903/how-to-reuse-intents-in-android

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