I am developing application that is using GCMIntentService
for Push Notifications. So I want to refresh the Data of one ListView
that is in a tab of my TabActivity
. So is it possible to do that from the GCMIntentService
when i receive and GCMIntentMessage
?
For example
SecondTabActivity.callOnResume(); //or something like this
or
SecondTabActivity.callOnCreate(); // or something like this
I need to do this without using startActivity(intent)
; cause If I do the SecondTabActivity is getting out of my TabHost
and it's starting like new Activity
. The function for refreshing the ListView
is located at onCreate(
) and onResume()
in the SecondTabActivity so that is why I want to call them. If there is any other way beside this one please refer to it. Thanks
A good way is to use broadcast intents.
In your TabActivity's onCreate, use the Context.registerReceiver method to register a broadcast receiver for an intent named something like "MyGCMMessageReceived."
In that broadcast receiver, call the method that refreshes your list.
this.registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
// INSERT CODE TO REFRESH LIST VIEW
}
}, new IntentFilter("MyGCMMessageReceived"));
Make your GCMIntentService's onMessage method broadcast an intent named "MyGCMMessageReceived".
Intent intent = new Intent("MyGCMMessageReceived");
this.sendBroadcast(intent);
You should use LocalBroadcastManager in Service to Activity Communications.
In your IntentService you send the new information via Local broadcast and in your TabActivity your have to register a receiver. In onReceive method you have to refresh your view.
Here you have an easy example: LocalBroadcastManager example
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With