Android how to create notification that resumes activity
- by Adam Praiswater
I a have a notification in a receiver that fires off fine, but it restarts the activity (thus clearing the edittexts and resetting the toggle button) How can i set it so that when its tapped on it resumes the activity rather that clearing and resetting everything? My current code doesnt work.
Current Code
String currentDateTimeString = DateFormat.getDateTimeInstance().format(new Date());
Intent intenti= new Intent(context, Locator.class);
intenti.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
intenti, 0);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.xxxxxxnotifyicon)
.setContentTitle("xxxxxxx Link")
.setContentText("Auto Check In Complete at " + currentDateTimeString);
mBuilder.setContentIntent(contentIntent);
mBuilder.setDefaults(Notification.DEFAULT_SOUND);
mBuilder.setAutoCancel(true);
NotificationManager mNotificationManager =
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(1, mBuilder.build());