Android Activity management

眉间皱痕 提交于 2019-12-13 04:29:02

问题


I have one question in mind for activity management. Suppose I have 4 activities say for example A1,A2,A3,A4. Now A1 have one button which start activity A2. A2 have 2 buttons which start either A3 or A4, A3 have 2 buttons which start activity A4 and A1. A4 have 3 buttons to sart activity A1,A2,A3 I do not use finish method in any of this activity. So now user click any of the activity any of the button than check the activity ,that is this already in back ground? If yes than this activity would not generate new instance and start activity which is already in background. otherwise it create new insistence.


回答1:


You can get this behaviour by including the FLAG_ACTIVITY_REORDER_TO_FRONT in your Intent's flags and then just calling startActivity(intent) like you normally would.




回答2:


Intent intent = new Intent();

intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);

startActivity(intent);




回答3:


You can search "android:lunchMode" by Google. Then you will get the anwser.




回答4:


Whenever the button is clicked in any activity, it creates the new instance of the activity irrespective of the fact the activity is already on the activity stack. Since new Intent is fired every time, it opens new activity. When we press back button then only it goes to the already opened activity from the stack.



来源:https://stackoverflow.com/questions/16456974/android-activity-management

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