android singleton activity

夙愿已清 提交于 2019-12-24 16:48:02

问题


The main activity of the app is TabActivity that contains some OneActivity

It is necessary to call from another part of app the OneActivity not creating the another instance of it, just calling onResume() of the one that lies in TabActivity

Tried set different launchMode ("singleTop", "singleTask", "singleInstance") and set flags for intent:

intent.setAction(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_LAUNCHER);

How to do it not creating a new instance of activity?


回答1:


Try the CLEAR_TOP flag. I removes all the activities above your activity in the activity stack, so it should solve your purpose.

Intent i = new Intent(context, YourSingleInstanceActivityName.class);
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);


来源:https://stackoverflow.com/questions/8131352/android-singleton-activity

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