I’ve follow this code: How to get RegistrationID using GCM in android
but i want update the TextView of MainActivity with received message.
please help me why i don’t know how i update a UI from service
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I suggest to use Broadcast receivers here. So
IntentServicewill broadcast the event, and all activities or something else can register for it.To avoid overkill of
BroadcastReceiversitself (as they are intented to be used in inter-process communication and can be an overkill and security leak) – I reccoment usingLocalBroadcastManager– http://developer.android.com/reference/android/support/v4/content/LocalBroadcastManager.html . It’s a helper for strictly-local broadcasts, makes easier to handle them and provide more performance and security.Update:
To use LocalBroadcastReceiver inside GCM IntentService you should do something like this:
And here you can check how to register the receiver inside your activity, it’s pretty easy: how to use LocalBroadcastManager?
Good luck