I have a notification which should give me some parameters when opening an activity via said notification.
private void notify_newOrders(int count) {
int icon = R.drawable.ic_notification;
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
CharSequence tickerText = infotext;
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, tickerText, when);
Context context = getApplicationContext();
CharSequence contentTitle = "Title";
CharSequence contentText = "Infotext";
Intent notificationIntent = new Intent(this, TestActivity.class);
notificationIntent.putExtra("resuming", "123");
notificationIntent.setAction("resuming");
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
notification.flags |= Notification.DEFAULT_ALL;
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.number = count;
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
mNotificationManager.notify(WORKNOTIFICATION_ID, notification);
}
In my activity I have the following:
@Override
public void onCreate(Bundle savedInstanceState)
{
try{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Bundle extras = getIntent().getExtras();
if(extras != null)
{
Log.d("YAY","got extras");
}
The problem is, I never get any extras. I’ve been through and through similar kind of (resolved) problems here and trying to find out why they worked and mine didn’t has proven useless. Help!
In logCat I get these, no idea if they are relevant:
INFO/ActivityManager(59): Starting activity: Intent { act=resuming flg=0x24000000 cmp=com.test.test/.TestActivity bnds=[0,101][320,165] (has extras) }
WARN/ActivityManager(59): startActivity called from non-Activity context; forcing Intent.FLAG_ACTIVITY_NEW_TASK for: Intent { act=resuming flg=0x24000000 cmp=com.test.test/.TestActivity bnds=[0,101][320,165] (has extras) }
Turns out the right thing was to make