Reputation: 71
This is my code for a notification. This is fired up by a service which runs when the phone is rebooted. If the phone is rebooted and the notification needs to be fired up by the service then it will work but when you click the notification, it's supposed to open an activity (the app is not running at this point) so I think that is why it crashes. When the app is running it works fine.
Any help would be appreciated.
NotificationManager mNotificationManager = (NotificationManager) getApplication().getSystemService(Context.NOTIFICATION_SERVICE);
Intent notificationIntent = new Intent(getApplicationContext(), Notification.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent result = PendingIntent.getActivity(context, 0,notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(getApplicationContext())
Upvotes: 1
Views: 1082
Reputation: 71
I fixed it
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0,notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT);
If anyone ever comes around this problem, try setting these flags.
Upvotes: 1