Communicate with Activity from Service (LocalService) - Android Best Practices

前端 未结 3 1231
感情败类
感情败类 2020-12-05 07:39

Common scenario - Activity with a background Service to poll server.

The Service will run periodically via AlarmManager and also perform tasks for the Activity (user

3条回答
  •  抹茶落季
    2020-12-05 08:13

    I think the best design would be the Android LocalService example: http://developer.android.com/reference/android/app/Service.html#LocalServiceSample

    I wouldn't. Use the loosest possible coupling you can stand. Hence, on average, aim for the command pattern with startService() instead of the binding pattern with bindService(). Notably, binding is a bit of a pain when it comes to dealing with configuration changes (e.g., screen rotations).

    What is the best way for the Service to call the Activity? Do I use Intents, BroadcastReceivers, Messages? How?

    See Notify activity from service

提交回复
热议问题