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
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
I suggest to use Broadcast receivers here. So IntentService
will broadcast the event, and all activities or something else can register for it.
To avoid overkill of BroadcastReceivers
itself (as they are intented to be used in inter-process communication and can be an overkill and security leak) - I reccoment using LocalBroadcastManager
- 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:
@Override
protected void onMessage(Context context, Intent intent) {
Intent bIntent = new Intent("custom-event-name");
// You can also include some extra data.
bIntent .putExtra("message", intent); //or get some info from Gcm intent and put it into this one.
LocalBroadcastManager.getInstance(context).sendBroadcast(bIntent);
}
And here you can check how to register the receiver inside your activity, it's pretty easy: how to use LocalBroadcastManager?
Good luck