admin管理员组

文章数量:1125591

I want to use AlarmManager to broadcast a message to my BroadcastReceiver that will perform some work at scheduled times.

However, I want to ensure I'm not blocking the main thread when doing this work. From some searching it seems like the onReceive function will be called by android on the main thread, but AlarmManager seems to run outside the context of the application (since it will send the alarms even when the application is in doze mode).

Will this end up blocking the main thread? And if so, is there a canonical way to use alarm manager to schedule work in the background?

I want to use AlarmManager to broadcast a message to my BroadcastReceiver that will perform some work at scheduled times.

However, I want to ensure I'm not blocking the main thread when doing this work. From some searching it seems like the onReceive function will be called by android on the main thread, but AlarmManager seems to run outside the context of the application (since it will send the alarms even when the application is in doze mode).

Will this end up blocking the main thread? And if so, is there a canonical way to use alarm manager to schedule work in the background?

Share Improve this question edited 2 days ago Atul Bhatia asked Jan 9 at 7:09 Atul BhatiaAtul Bhatia 1,7955 gold badges27 silver badges51 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

https://developer.android.com/reference/android/content/BroadcastReceiver#onReceive(android.content.Context,%20android.content.Intent)

This method is called when the BroadcastReceiver is receiving an Intent broadcast. During this time you can use the other methods on BroadcastReceiver to view/modify the current result values. This method is always called within the main thread of its process, unless you explicitly asked for it to be scheduled on a different thread using Context.registerReceiver(BroadcastReceiver, IntentFilter, String, android.os.Handler)

本文标签: androidUsing alarm manager with broadcast receiverwill it run on the main threadStack Overflow