简体   繁体   English

如何在Android中引入活动?

[英]How to bring an activity to front in android?

I am using moveTasktoBack() function to send my activity to background. 我正在使用moveTasktoBack()函数将我的活动发送到后台。 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. 请帮忙。

Exact Same issue that is mentioned on this Question. 完全相同的问题在本课题中提到。

Sloved it with following code snippet. 点击以下代码片段。 i.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT) ; i.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT) ; actauul which brings back the activity to front. actauul把活动带回到前面。

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);

我认为它应该是FLAG_ACTIVITY_SINGLE_TOP

You can use intent with the appropriate flags. 您可以使用带有适当标志的intent FLAG_ACTIVITY_NEW_TASK to create a new task to contain your activity if one doesn't already exist. FLAG_ACTIVITY_NEW_TASK用于创建包含活动的新任务(如果尚未存在)。 FLAG_ACTIVITY_REORDER_TO_FRONT to bring your activity to the front of the task if it's not already there. FLAG_ACTIVITY_REORDER_TO_FRONT将您的活动置于任务的前端(如果它尚未存在)。

Intent intent = new Intent(context, YourActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK);

context.startActivity(intent);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM