4

If it must implement with AIDL? And please kindly provide an example, thanks.

EDIT: There are several solutions, Does anyone know which is better?

shiami
  • 7,174
  • 16
  • 53
  • 68

2 Answers2

9

You might be looking for the ResultReceiver class (http://developer.android.com/reference/android/os/ResultReceiver.html).
You extend it, pass it along with the intent you invoke the Service with (it's parcelable), then when your task completes in the Service, you call the ResultReceiver's onReceiveResult() method with the results.

Allan Pereira
  • 2,572
  • 4
  • 21
  • 28
Zsombor Erdődy-Nagy
  • 16,864
  • 16
  • 76
  • 101
  • Thanks! Is there any alternative solution? I would like to know. – shiami Oct 14 '10 at 04:17
  • Well tell us if you've found any, because I couldn't find any better solutions. I don't really like it either, tho it does work. – Zsombor Erdődy-Nagy Oct 14 '10 at 17:31
  • I think the broadcast/receiver should work but have no idea if it is better or not. – shiami Oct 15 '10 at 01:35
  • I'm trying to use static Handler to send message back to main thread now. I think there must be mutiple solutions but which is better? – shiami Oct 15 '10 at 01:43
  • @shiami Did you ever have any luck with a static Handler in the main thread? This seems to result in null pointer exceptions for me if I don't have any Activities open. – Tenfour04 Mar 21 '11 at 11:40
  • @Scythe & to post owner, Could you find code snippet? Could you share it to us.. Thanks & Regards – eros Aug 26 '11 at 04:16
1

checkout this post :Using ResultReceiver in Android , discussing the implementation of resutlreceiver.

Community
  • 1
  • 1
SohailAziz
  • 8,034
  • 6
  • 41
  • 43