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.
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.
来源:https://stackoverflow.com/questions/11369785/bring-task-to-front-on-widget-click