从Home键屏幕启动的活动 [英] Started activity from home key screen

查看:102
本文介绍了从Home键屏幕启动的活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有开始活动后台服务,

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

摧毁这一活动,并重新启动它在长preSS home键菜单后,该活动再次启动。但是,我要开始的主要活动,而不是。我怎么能认识到这一点?

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?

推荐答案

你能不能更详细地解释一下吗?如果我理解你的问题,尝试设置FLAG_ACTIVITY_NO_HISTORY。

Could you explain in more detail? If I understand your problem try setting the FLAG_ACTIVITY_NO_HISTORY.

另外一个手动的解决办法是检查的意图FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY在MyActivity和发射的主要活动,如果你看到这个标志集。下面code应该这样做:

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

这篇关于从Home键屏幕启动的活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆