Accessing a database through a broadcastreceiver on RECEIVE_BOOT_COMPLETED

后端 未结 1 638
没有蜡笔的小新
没有蜡笔的小新 2021-01-14 05:25

When the phone is finish booting up I want to automatically re-register some alarms, based on hour, minute ++ infomation from a database.

I try to do this with a br

1条回答
  •  一生所求
    2021-01-14 06:01

    You do not want to do database I/O in any manifest-registered broadcast receiver. You do not know how long it will take (based on other device activity), and your onReceive() method is running on the main application thread, so your time is limited and your CPU footprint is large.

    Please pass control to an IntentService for doing the database I/O and scheduling your alarms. The IntentService will call your onHandleIntent() on a background thread, so you can take the time you need, and the service automatically goes away when onHandleIntent() completes.

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