In my application, i have used C2DM. Here, when i receive a C2DM message/notification, i am trying to create a notification using notification manager. I can properly create notifications, but i am unable to increment the number of unread notifications(using Notification.number) when there are many unread notifications. Since i am creating notification object inside onReceive() function, its getting destroyed as soon as the control comes out of onReceive function. So, the statements
public class MyC2dmReceiver extends BroadcastReceiver{
private Context context;
@Override
public void onReceive(Context context1, Intent intent) {
this.context = context1;
if(intent.getAction().equals("com.google.android.c2dm.intent.REGISTRATION")) {
handleRegistration(context, intent);
}
else if (intent.getAction().equals("com.google.android.c2dm.intent.RECEIVE")) {
handleMessage(context, intent);
}
}
private void handleMessage(Context context, Intent intent)
{
.....
.....
Notification notification =
new Notification(R.drawable.ic_launcher,intent.getStringExtra("payload"),
System.currentTimeMillis());
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.defaults = Notification.DEFAULT_ALL;
notification.number += 1;
}
}
have been of no use as it is creating a new notification object everytime. I can not make it(notification object) a static object also. If i make it a static object, even after all the unread notifications are viewed, the notification.number does not get reset. This is basically the problem. Could anybody help me?
Store your number of unread messages in a database, flat file, shared preference, or other persistent store. Read in that number when creating your new
Notification.