[英]Open android application when device opens
I'm developing an android application that I want that starts when the device is opened and remains on foreground until it is closed. 我正在开发一个我想要的Android应用程序,它在设备打开时启动并保持在前台直到它关闭。 To achieve this I have used some tricks that I found surfing the Internet:
为了达到这个目的,我使用了一些我在网上冲浪的技巧:
I test the solution and it works fine almost always. 我测试解决方案,它几乎总能正常工作。 When I close the device with the app executing and it restarts the device the application is opened twice.
当应用程序执行时关闭设备并重新启动设备时,应用程序将打开两次。 I think that the extra opening is due because the Activity Alias wasn't uninstalled because the app doesn't close properly when I shutdown the device.
我认为额外的开放是因为没有卸载Activity Alias,因为当我关闭设备时应用程序没有正确关闭。
Is there a solution to avoid this behavior? 有避免这种行为的解决方案吗?
Thanks 谢谢
您应该使用ACTION_SHUTDOWN并在shutdown时执行必要的任务。在此处查看更多详细信息。
You can maybe use the Shutdown intent to finish your activity when the device is shutting down. 您可以使用Shutdown意图在设备关闭时完成您的活动。
<receiver android:name=".myReceiver">
<intent-filter>
<action android:name="android.intent.action.ACTION_SHUTDOWN" />
</intent-filter>
</receiver>
Then you can just use the activity.finish();
然后你可以使用
activity.finish();
to close your app. 关闭你的应用程序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.