I am using moveTasktoBack() function to send my activity to background. I want to bring my activity to front when a timer in my activity finishes. I am using the phone back key to send the activity to back. How do I do that? Help please.
Asked
Active
Viewed 7,749 times
4
-
1Answered here: http://stackoverflow.com/questions/2232238/how-to-bring-an-activity-to-foreground-top-of-stack – Eric Schlenz Dec 03 '11 at 21:14
-
@EricSchlenz actually that link discusses how to rearrange activities within a task. This doesn't solve OP's problem. He wants to know how to bring a task from the background to the foreground. – David Wasser Apr 22 '15 at 16:12
-
To bring a task to the front, see http://stackoverflow.com/a/29769255/769265 – David Wasser Apr 22 '15 at 16:13
-
why so many answer to confuse! when each intent flag has different meaning and purpose. – Shubham AgaRwal Oct 08 '15 at 11:51
3 Answers
4
Exact Same issue that is mentioned on this Question.
Sloved it with following code snippet. i.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT)
; actauul which brings back the activity to front.
Intent i=new Intent(ApplicationStatus.this,NotifyActivity.class);
//i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
i.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
i.putExtra("ID_TimeLeft",String.valueOf(TimeLeft));
startActivity(i);

DeltaCap019
- 6,532
- 3
- 48
- 70
0
You can use intent with the appropriate flags. FLAG_ACTIVITY_NEW_TASK
to create a new task to contain your activity if one doesn't already exist. FLAG_ACTIVITY_REORDER_TO_FRONT
to bring your activity to the front of the task if it's not already there.
Intent intent = new Intent(context, YourActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);

lastoneisbearfood
- 3,955
- 5
- 26
- 25