service send information to Activity

by maggy mtac » Tue, 15 Mar 2011 17:21:21 GMT


Sponsored Links
 Hello,

I want to known How send information for example String from service
to Activity?

How start even Activity in a service because i want to display when
the service recover a data , he transmit to even Activity?

Thanks

-- 



Re: service send information to Activity

by Mark Murphy » Tue, 15 Mar 2011 20:01:47 GMT


 


Send a broadcast Intent.

Or, have the activity supply a Messenger to the service via an Intent
extra, and the service sends a message to the activity via that
Messenger.

Or, have the activity use createPendingResult() to create a
PendingIntent and pass that via an Intent extra, and the service
executes that PendingIntent, providing a response that the activity
receives in onActivityResult().

Or, if you are using bindService(), have the activity register some
sort of listener with the service, which the service uses to send back
data.

There are probably other options as well.


Do not "start even Activity in a service", unless you KNOW that the
user is using your application in the foreground. Use a Notification
to alert the user that "the service recover a data", please.

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com  |  http://github.com/commonsguy 
 http://commonsware.com/blog  |  http://twitter.com/commonsguy 

Warescription: Three Android Books, Plus Updates, One Low Price!

-- 


Sponsored Links


Other Threads

1. Android Market source

I'm starting to learn how to use the android platform and one of the
things I like is how the market is setup visually, and functionally.
I've downloaded the whopping huge source code for the android
platform, but I can't seem to find the Android Market app anywhere!
I've done grep searches and all. It could be under a codename, but I'm
not sure.

Maybe it's this way for security purposes (so no one can reverse
engineer the financial transaction routines), but there are other
things on the market besides that that I could surely benefit from!

Please help,
Taylor

-- 

2. developing for differant sizes

Hello all,

I am currently at the end of devoping a simple program with a radio
group, two buttons and a text view. When I test it on my g1 and the
1.6 emulator it looks great, but when my friend tries it on his droid
many elements are displaced and cut off.

I am using absolutelayout, does this layout not scale accordingly to
the screen?

-- 

3. Android singletop singleinstance and singletask

4. content observer for calllog works on 1.6 but fails on 2.0

5. EventListenerList in Android

6. colud i join Android Developers group?

7. Getting access to audio data during a phone call