android singleton activity

2019-07-25 13:49发布

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条回答
Luminary・发光体
2楼-- · 2019-07-25 14:23

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);
查看更多
登录 后发表回答