开机后自动启动的应用程序在Android中完成应用程序、自动启动、Android

2023-09-12 03:30:19 作者:小熊从不喝水

我想打,在其设置的自动启动选项的应用程序。我在这是从preferenceActivity来源,并给予复选框preference自动启动选项的应用程序进行的设置活动。如果启用自动启动选项,我的应用程序应该开始时,手机的启动完成。如果自动启动选项被禁用那么它不应该开始启动完成。

I want to make an application which has auto start option in its settings. I have made Settings activity in my application which is derived from PreferenceActivity and give CheckBoxPreference for auto start option. If auto start option is enabled my application should start when booting of phone is completed. And if auto start option is disabled then it should not start on boot completed.

要做到这一点,我已经实现派生类的BroadcastReceiver,它接收BOOT_COMPLETED意图,在AndroidManifest.xml中声明接收器,也赋予权限在AndroidManifest.xml中。

在实际应用中还出现了一个派生类的应用,并从应用程序派生类的onCreate方法启动的服务也。如果我宣布接收器在AndroidManifest.xml中,然后启动完成我的应用程序中的onCreate调用之后和BroadcastReceiver的那的onReceive方法后调用。

In application also there is a derived class of Application and start service also from the onCreate method of application derived class. If I declare receiver in AndroidManifest.xml then after booting completed onCreate of my application called and after that onReceive method of BroadcastReceiver called.

现在的问题是,我的应用程序在启动时启动完成后自动启动是否启用或禁用每次。是否有可能无法启动应用程序时自动启动被禁用?

推荐答案

您可以使用共享preference来存储 isAutoStartEnabled 一个布尔值,并检查该在BroadcastReciver值,触发一个目的,只有当它是真的。

You can use the shared preference to store a Boolean value for isAutoStartEnabled, and check this value in the BroadcastReciver, fire an intent only if it's true.

在你的情况,问题不在于是否接收广播,但谁接收广播。祝您好运。

In your case, the problem is not whether you receive the broadcast but who receives the broadcast. Best of luck..

我希望它能帮助。