When my broadcast receiver is triggered it will launch a notification that directs the user to an chat activity which is build in the application.
The problem is when the user is inside the application doing things. (it's main purpose is not chatting)
- let's say receives the notification while he's in the menu of the app
- When he presses the notification the chat activity starts up
- When pressing the back button the user goes to the home screen of the phone?
I want it to go back to the activity where he triggered the notification. This could be anywhere inside the application.
Building the notification:
notificationIntent = new Intent(mContext, BerichtenActivity.class);
Toast.makeText(context, verzender + ": " + inhoud, Toast.LENGTH_LONG).show();
Notification notification = NotificationUtils.handleNotification(mContext, notificationIntent, verzender, inhoud, R.drawable.ic_stat_chat);
NotificationManager notificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(notificationId, notification);
public static Notification handleNotification(Context context, Intent resultIntent, String titel, String body, int smallIcon){
PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent, 0);
Uri uri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context)
.setAutoCancel(true)
.setContentText(body)
.setContentTitle(titel)
.setContentIntent(resultPendingIntent)
.setSound(uri)
.setLargeIcon(BitmapFactory.decodeResource(
context.getResources(), R.mipmap.ic_launcher))
.setSmallIcon(smallIcon);
return notificationBuilder.build();
}