I had a problem with a notification that does not open and does not fit the correct action when clicked.
My notification code (located in a class that extends Service):
Context context = getApplicationContext(); CharSequence contentTitle = "Notification"; CharSequence contentText = "New Notification"; final Notification notifyDetails = new Notification(R.drawable.icon, "Consider yourself notified", System.currentTimeMillis()); Intent notifyIntent = new Intent(context, MainActivity.class); PendingIntent intent = PendingIntent.getActivity(context, 0, notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT | Notification.FLAG_AUTO_CANCEL); notifyDetails.setLatestEventInfo(context, contentTitle, contentText, intent); ((NotificationManager)getSystemService(NOTIFICATION_SERVICE)).notify(NOTIFICATION_ID, notifyDetails);
If I click a notification when the application that created the service is open, the notification disappears (due to FLAG_AUTO_CANCEL), but the action does not switch.
If I click a notification on the main screen, the notification disappears and my application is brought to the forefront, however it remains in the activity that was opened before entering the main screen, instead of going to the main screen.
What am I doing wrong? How to specify activity to be disabled?
android android-activity notifications
Mr zorn
source share