BroadcastReceiver for BOOT_COMPLETED is too slow

前端 未结 2 740
醉梦人生
醉梦人生 2021-02-14 12:57

The below is my manifest file.

    
    

        
相关标签:
2条回答
  • 2021-02-14 13:39

    There will be some system resources that need to boot first and will have a higher priority over your receiver. However you could try setting a priority to your intent in the manifest. Like so:

    <intent-filter android:priority="999">
        <action android:name="android.intent.action.BOOT_COMPLETED" />
        <action android:name="android.intent.action.QUICKBOOT_POWERON" />
    

    Please have a look at the details from the developer docs regarding this: Docs

    Extract regarding priority:

    It controls the order in which broadcast receivers are executed to receive broadcast messages. Those with higher priority values are called before those with lower values. (The order applies only to synchronous messages; it's ignored for asynchronous messages.)

    Use this attribute only if you really need to impose a specific order in which the broadcasts are received, or want to force Android to prefer one activity over others.

    The value must be an integer, such as "100". Higher numbers have a higher priority. The default value is 0. The value must be greater than -1000 and less than 1000.

    0 讨论(0)
  • 2021-02-14 14:01

    Is there any what to start the application immediately after reboot?

    No.

    There are many, many apps that want to get control at boot time. How quickly yours will get its turn will depend on many variables, such as the number of installed apps, the CPU speed of the device, the amount of system RAM on the device, etc.

    Also, starting an activity from a BroadcastReceiver at boot time is fairly evil. If you want to be the first thing the user sees after a reboot, write a home screen implementation.

    0 讨论(0)
提交回复
热议问题