Bring task to front on widget click

狂风中的少年 提交于 2019-12-04 20:59:53

Just start the main (root) activity of your application like this:

Intent intent = new Intent(context, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);

If the activity is already running in a task, this will just bring that task to the foreground (without creating any new instances of the activity). If the activity is not already running, then this will start a new task with that activity at the root.

In my situation,FLAG_ACTIVITY_NEW_TASK is useless.It will recreate the activity though the activity exists in the task.

But singletask launchmode works well.

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