AlarmManager and BroadcastReceiver instead of Service - is that bad ? (Timeout)

后端 未结 3 631
长发绾君心
长发绾君心 2020-12-05 08:01

BACKGROUND INFO:

I need to update some data from the web, about every hour or so, even when my app is closed. The update of the data itself takes ab

3条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-05 08:56

    Why this timeout ?

    You are running on the main application thread. You cannot run on the main application thread for more than a few seconds. Also, while doing this, you are harming the performance of the device (because you are running with foreground priority), such as causing frame-rate loss in games or videos.

    Any easy way to avoid this ?

    Don't do significant work (>100ms) on the main application thread. Have your BroadcastReceiver delegate to an IntentService, perhaps a WakefulIntentService.

    Did I set up my BroadcastReceiver correctly in the manifest ?

    Please please please please please get rid of the android:process=:remote. You do not need it, it is not helping you, and it is degrading performance of the device even further.

    Should I absolutely go for a Service for this kind of "Refresh from Web" functionality ? (considering this article : http://www.androidguys.com/2009/09/09/diamonds-are-forever-services-are-not/) If YES (I should switch to a service): Any good snippets of code/tutorial for this ...

    IMHO, yes. Then again, I wrote that blog post. For an example, see the WakefulIntentService project.

提交回复
热议问题