I have a small app where the main activity is already in front and a notification may show. When the user taps on the notification I would like to have the main activity get the intent extras and act on them, but not sure how since it is already running.
My code that returns the PendingInent for use in the NotificationCompat.Builder:
private static PendingIntent getPendingIntent(Context ctx, String brandId) {
Intent showIntent = new Intent(ctx, MainActivity.class);
showIntent.setAction(Intent.ACTION_MAIN);
showIntent.addCategory(Intent.CATEGORY_LAUNCHER);
showIntent.putExtra(PUSH_NOTIFICATION, true);
showIntent.putExtra(BRAND_ID, brandId);
return PendingIntent.getActivity(ctx, 0, showIntent, PendingIntent.FLAG_UPDATE_CURRENT);
}
I thought that maybe my MainActivity would be relaunched, but it isn't
How can I do this?
Have you tried overriding the "onNewIntent" method within your MainActivity class?
For example:
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
//handle new intent here
}
As your activity is already running the new intent should come in here.