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

I think the best design would be the Android LocalService example: developer.android.com/reference/android/... 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 android: notify activity from service.

I think the best design would be the Android LocalService example: developer.android.com/reference/android/... 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 android: notify activity from service.

Well I actually based it off your tutorial: github. Com/commonsguy/cw-andtutorials/tree/master/… Is there anything bad about this approach? – paulpooch Feb 5 at 22:11 @paulpooch: Well, let's just say I'm rewriting all the Patchy tutorials in the next couple of months.

– CommonsWare Feb 5 at 22:17.

If you need tight coupling between your activity using bindService(), the way you communicate depends on who is originating the communication. If the Service is originating (due to say an Alarm that has some new information to share), it would typically send a broadcast. If the Activity is originating (due to say your example "go fetch something from server"), it could be handled asynchronously using AsyncTask or similar.

That is, you could fetch from the server in the AsyncTask.doInBackground(), and post the results back to the activity in AsyncTask.onPostExecute. This scenario be a bit more complicated if the requested operation is expected to take a very long time - in which case I would de-couple it, and send a broadcast back from the Service instead.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions