Broadcast in GCM:
onMessageReceived method:
Intent intent = new Intent(MessageReceiver.name);sendBroadcast(intent);
Create class Reciever:
public class MessageReceiver extends BroadcastReceiver{public static String name = "com.app.privilege.receiver.MESSAGE";
@Override public void onReceive(Context context, Intent intent) {
}
}
In MainActivity:
Above OncreateMessageReceiver receiver = new MessageReceiver() {
@Override public void onReceive(Context context, Intent intent) {
displayData();
}
};
In Oncreate:
registerReceiver(receiver, new IntentFilter("com.app.privilege.receiver.MESSAGE"));public void displayData() {
adapter.notifyDataSetChanged();
recyclerView.invalidate();
}
On Destroy:
@Overrideprotected void onDestroy() {
super.onDestroy();
unregisterReceiver(receiver);
}
In Manifest:
<receiver android:name=".receiver.MessageReceiver" android:enabled="true"><intent-filter>
<action android:name="com.app.privilege.receiver.MESSAGE" />
</intent-filter>
</receiver>
No comments:
Post a Comment