1

In Virgil Dobjanschi talk during Google I/O he mentioned using Services for doing the fetching and then using a callback to notify the Activity when this was completed. He never went into specifics on how to implement this callback and I can't seem to find anything helpful on this topic anywhere.

I think he said that you didn't need to implement binding at all?

Any clues?

alexanderblom
  • 8,632
  • 6
  • 34
  • 40

3 Answers3

8

Option #1: Service sends a broadcast Intent, which the Activity catches via a BroadcastReceiver registered via registerReceiver().

Option #2: If the Activity is binding to the Service, have the Activity pass a listener to the Service, which the Service invokes when the work is complete.

Option #3: Service doesn't do much, but the ContentProvider calls notifyChange() when the data changes, which can ripple back through to the Activity and/or its Cursor on the data.

Option #4: Singletons, which should be avoided.

...

Option #237: Service sends a letter via FedEx to the Activity. :-)

...

All that being said, once they release the Twitter app as open source, you'll know for certain what the Twitter app does.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • As per Rponds answer, the Google I/O app passes a listener as a parceable extra. Was that what you meant with option #2 or did you mean full binding? – alexanderblom Jun 25 '10 at 09:41
  • No, Option #2 was full binding. Option...umm...#74 was using `ResultReceiver`. Frankly, I am stunned at that choice, since `ResultReceiver` uses AIDL, and we've been told repeatedly not to use that for local operations due to overhead issues. Perhaps there is something special about `ResultReceiver` that I am unaware of. – CommonsWare Jun 25 '10 at 10:00
  • Quick follow-up on this: AIDL does not add overhead for local access. They detect that the client and server are in the same process and route things directly. Hence, my fears about `ResultReceiver` are unfounded. For more, see this thread: http://groups.google.com/group/android-developers/browse_thread/thread/79049af16fde46e8 – CommonsWare Jun 30 '10 at 13:05
1

Check out the Google I/O 2010 app. It uses the pattern he was referring to. It uses Option #2 from CommonsWare's answer.

Robby Pond
  • 73,164
  • 16
  • 126
  • 119
  • Thanks! Never realized that app used his method. What he does is pass a listener interface as a parceable, which I didn't even knew was possible. – alexanderblom Jun 25 '10 at 09:39
0

i think they're talking ab out using AIDL to communicate between the activity & the service...

Ben
  • 16,124
  • 22
  • 77
  • 122