开发者

Android Bring Task to Front

I have main activity + service. Service is calling second activity. - If main is i开发者_JAVA百科n foreground, all is fine. Second is opened above main. - If I close main by "Back" button, then second is opened above desktop. It's cool. - BUT when I close main by switching to desktop (press "Home" button), then second activity is opened invisible and you can see it only when you switch to app's task.

Can you help me to move my task to foreground in case if app is in background? I tried make second activity as new task, but this doesn't help.


Flag top activity in your task as singleTask, than send any intent to this activity so all task will be brought to foreground without recreating this activity


Sounds a lot like a problem I had. Look at: http://groups.google.com/group/android-developers/browse_thread/thread/183340108cb847fd

You can try setting the affinity of your task, like:

<activity android:name="activity_two" android:taskAffinity=""></activity>

in your AndroidManifest.xml (while making the activity its own task, like you mention).

If you don't want the other activity to show up in the recent history list as a separate task, you can also add:

android:excludeFromRecents="true"

to the activity in the manifest.


Exact same issue that is mentioned on this Question.

Solved it with following code snippet. i.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); 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);//optional
                    i.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);//will cause it to come to foreground
                    i.putExtra("ID_TimeLeft",String.valueOf(TimeLeft));
                    startActivity(i);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜