Bring task to front on widget click

落花浮王杯 提交于 2019-12-09 23:46:05

问题


I sent a task (activity) to back with:

    @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    moveTaskToBack(true);
}

but I need bring it to front by setOnClickPendingIntent in widget.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/11369785/bring-task-to-front-on-widget-click

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