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 badges1 Answer
Reset to default 1https://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
版权声明:本文标题:android - Using alarm manager with broadcast receiver -- will it run on the main thread? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736666588a1946696.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论