简体   繁体   English

即使重新启动后没有启动应用程序,我仍然可以拥有BOOT_COMPLETED吗?

[英]Can I still have BOOT_COMPLETED even if I don't launch the app after reboot?

So let's say my receivers and service are correct, will the BOOT_COMPLETED still run even after I reboot the device and I won't open/launch it (the app) for the first time? 因此,假设我的接收器和服务是正确的,即使重新启动设备后, BOOT_COMPLETED仍然可以运行,并且不会首次打开/启动该应用程序吗? Then the alarm works when its due date and time? 然后,闹钟在其到期日期和时间生效?

NOTE : I do not try to launch the app after the reboot. 注意 :重新启动后,我不会尝试启动该应用程序。

this is my manifest 这是我的清单

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" android:persistent="true">
  <receiver android:name="com.majimechibireminder2.OnBootReceiver" >
     <intent-filter>
        <action android:name="android.intent.action.BOOT_COMPLETED" />
        <category android:name="android.intent.category.HOME" />
     </intent-filter>
 </receiver>

  <receiver android:name=".AlarmReceiver"></receiver>
   <service android:name=".ChibiReminderService" >
 </service>
   <activity android:name=".ChibiRemind"></activity>
</application>

If not, could you suggest me some proper code to work on those my ideals. 如果没有,您能否建议我一些合适的代码来实现我的理想。

Your app needs to be lanuched at least once after it was installed to phone to make it able to receive broadcasts. 将您的应用安装到手机上后,至少需要对其进行一次清理,以使其能够接收广播。 If you are working with alarms you don't need to worry about it because the user will need to open app to set particular alarm. 如果您正在使用警报,则无需担心,因为用户将需要打开应用来设置特定警报。

When the phone gets turned off, alarms will go off. 当手机关闭时,闹铃会响起。 After reboot is completed your app will receive BootCompleted action. 重新启动完成后,您的应用程序将收到BootCompleted操作。 No need to launch app after reboot. 重新启动后无需启动应用程序。

If the user doesn't open your app after it has being installed it means he/she didn't set any alarms. 如果用户在安装应用后未打开您的应用,则表示他/她未设置任何警报。 Therefore, no need to worry about reboot for such cases as there is nothing to reset after reboot. 因此,在这种情况下无需担心重新启动,因为重新启动后无需重新设置。

Update: 更新:

Try adding attribute android:enabled="true" to your receiver. 尝试将android:enabled="true"属性添加到您的接收器。 Final code should look something like this: 最终代码应如下所示:

<receiver android:name=".OnBootReceiver" android:enabled="true">
    <intent-filter>
        <action android:name="android.intent.action.BOOT_COMPLETED" />
    </intent-filter>
</receiver>

Alarms set by AlarmManager will be lost after a reboot (without any additional manipulation). 重新启动后,由AlarmManager设置的警报将丢失(无需任何其他操作)。

This is one area where JobScheduler APIs comes to the rescue. 这是JobScheduler API可以拯救的领域。 They are not lost after reboots if you set them to persist after reboots. 如果将它们设置为在重新启动后仍然存在,则重新启动后它们不会丢失。

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

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