最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

broadcastreceiver - Broadcast intent android.intent.action.BOOT_COMPLETED received every single time I runupdate the app. Why? -

programmeradmin6浏览0评论

I have a very simple alarm app which needs to re-register it's alarms after phone reboots. However, seems like Android OS intent android.permission.RECEIVE_BOOT_COMPLETED does not work properly - I am receiving BOOT_COMPLETED every single time I update/deploy an app from Android Studio which is super odd and I believe incorrect behavior? This is my setup:

I declared a necessary permission in my AndroidManifest.xml:

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

I declared my Broadcast receiver in my AndroidManifest.xml:

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

I listen to intents like this:

public class MyReceiver extends BroadcastReceiver {
    public void onReceive(Context context, Intent intent) {
        if (intent.getAction().startsWith("android.intent.action.BOOT_COMPLETED")) {
            Log.i(this.TAG, "REBOOT"); // called every time I update an app
        }
    }
}
  • Expected result: It should only happen after device reboot.
  • Actual Result: I see "REBOOT" logged every single time I deploy an app on my device from Android Studio.

Anybody knows why such behavior happens? I can reproduce it on every device, every emulator, all the time.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论