重新启动手机上启动prevent活动? [英] Prevent activity from restarting on phone boot?

查看:123
本文介绍了重新启动手机上启动prevent活动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果用户重新启动他们的电话,而我的活动是在前台,手机重启后,活动再次自动弹出。我不希望这种情况发生,因为没有额外的数据我传递给活动的保存,所以活动不正确的显示。

If a user reboots their phone while my activity is in the foreground, after the phone reboots, the activity automatically pops up again. I don't want this to happen because none of the extra data I pass to the activity is saved, so the activity does not have the correct display.

显然,活动甚至我的广播接收器,有一个意图过滤器 android.intent.action.BOOT_COMPLETED 开始前启动。

Apparently the activity is started even before my BroadcastReceiver that has an intent-filter with android.intent.action.BOOT_COMPLETED starts.

怎么会去$ P $自动启动pventing活动的时候,手机的靴子?

How would I go about preventing the activity from automatically starting when the phone boots?

编辑:我用我的意图过滤器中的 android.intent.category.HOME 类别我的活动,这显然是原因它启动在重新启动。

I use the android.intent.category.HOME category in my intent filter for my activity, which apparently is the reason for it starting up on reboot.

推荐答案

ACTION_SHUTDOWN 广播应该走出去,当设备被关闭。我说应该走出去,因为它假定有序关机。如果用户卷起按住电源按钮〜10秒,或突然跑出电池,我会假设, ACTION_SHUTDOWN 未播出。

The ACTION_SHUTDOWN broadcast is supposed to go out when the device is shutting down. I say "supposed to go out", because it assumes an orderly shutdown. If the user winds up holding the POWER button for ~10 seconds, or popping out the battery, I would assume that ACTION_SHUTDOWN is not broadcast.

要控制是否组件(例如,活动)是可用的,你可以使用软件包管理系统 setComponentEnabledSetting() 。禁用的组件不能运行,一般是不可见的(例如,禁用的应用程序widget的<接收> 在应用程序窗口小部件选择器不会显示出来)。

To control whether a component (e.g., activity) is available, you can use PackageManager and setComponentEnabledSetting(). A disabled component cannot be run and is generally invisible (e.g., a disabled app widget's <receiver> will not show up in the app widget picker).

在理论上,可以结合这两种。然而,即使在最好的时候,我会假设, ACTION_SHUTDOWN 的行为是相当有时间限制的(所以要快点讲),你将需​​要处理的无序停机的情况。

In theory, you can combine these two. However, even at the best of times, I would assume that ACTION_SHUTDOWN behaviors are rather time-limited (so be quick about it), and you will need to handle the "disorderly" shutdown scenarios.

这篇关于重新启动手机上启动prevent活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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