简体   繁体   English

从主页键屏幕开始活动

[英]Started activity from home key screen

I have a background Service which starts an activity, 我有一个开始活动的后台服务,

Intent i = new Intent(this, MyActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);

After destroying this Activity and restart it over the "long press home key menu", this Activity starts again. 在销毁此活动并通过“长按主页键”重新启动它之后,此活动将再次启动。 But I want to start the main activity instead. 但我想开始主要的活动。 How could I realise this? 我怎么能意识到这一点?

Could you explain in more detail? 你能详细解释一下吗? If I understand your problem try setting the FLAG_ACTIVITY_NO_HISTORY. 如果我了解您的问题,请尝试设置FLAG_ACTIVITY_NO_HISTORY。

Alternatively a manual solution would be to check the FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY on the intent in MyActivity and launch to the main activity if you see this flag set. 或者,手动解决方案是检查MyActivity中的intent的FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY,如果看到此标志设置,则启动到主活动。 The following code should do that: 以下代码应该这样做:

if ((getIntent().getFlags() & FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) > 0) {
   activity.startActivity(new Intent(context , MainActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));    
}

The problem is like you started the activity from service-->Notification came-->user launch the app agian-->No notification-->main activity came on foreground Now if the application is started from the "long press home key menu" main activity is starting and showing the Notification. 问题就像你从服务开始活动 - >通知来了 - >用户启动app agian - >没有通知 - >主要活动出现在前台现在如果应用程序是从“长按主页键菜单”启动的“主要活动正在开始并显示通知。

so one Clear resolution is make Main activity as "Exclude From recent = true" and "No History = true;" 所以一个明确的解决方案是将Main活动设为“Exclude From recent = true”和“No History = true;” user will not be able to see your activity in the "long press home key menu" 用户将无法在“长按主页键菜单”中看到您的活动

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

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