Notification android intent always comes null when app is closed or in background

0

Intent intent = new Intent(this, ActionBar.Tab.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);

intent.putExtra("MEU_ITEM",notification.getData().get("CODIGO"));

NotificationCompat.Builder notificationBuilder =
            new NotificationCompat.Builder(this, channelId)
                    .setSmallIcon(R.drawable.notificacao_android)
                    .setContentTitle(notification.getNotification().getTitle())
                    .setContentText(notification.getNotification().getBody())
                    .setAutoCancel(true)
                    .setSound(defaultSoundUri)
                    .setContentIntent(pendingIntent);

    NotificationManager notificationManager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

The code above works perfectly when I'm with an open app where the onNewIntent method receives the Intent and I can do the processing, the problem is when the application is in the background or closed, when clicking on the notification the Intent exists but when the app starts or back from the background the Intent comes null everywhere. How can I get the intent coming from a notification when the Activity is closed or in the background?

    
asked by anonymous 26.11.2018 / 18:31

0 answers