Respond to Android Notification Intent in Xamarin Forms while App is in ForeFront or Not Stopped

I have issued android notifications using the Notification.Builder passing in my app's MainActivity (See bottom for code)
I need to be able to read the bundle, but see no way to do this once the app is already running... as OnCreate(Bundle savedInstanceState)
doesn't run on clicking the android notification.

Since the app is already running, the only event I can trap is OnResume() which doesn't give me access to the extra info I provided in the bundle.

I tried using another activity in the xamarin android sub project, but that gives me issues as xamarin forms uses only one activity: MainActivity.

I need some way to respond to the notification click in the xamarin android MainActivity or figure out how to use another activity to handle the click and operate on the passed information.

Thanks!

/* Notification Code Below */~~~~

var nMgr = (NotificationManager)context.GetSystemService(Context.NotificationService);
var pendingIntent = PendingIntent.GetActivity
(context, 0, new Intent(context, typeof(MainActivity)).PutExtra("IsRespondingToNotification", true) , 0, null);

// Build the notification:
Notification.Builder builder = new Notification.Builder(context)
.SetContentTitle("App Messages")
...
.SetContentIntent(pendingIntent);
Notification notification = builder.Build();
nMgr.Notify(0, notification);

Tagged:

Best Answer

  • ElliotGElliotG
    Accepted Answer

    Hours of futzing around and then right after posting, I find OnNewIntent()...
    Thanks for reading! I've got what I need.

Answers

  • ElliotGElliotG Member
    Accepted Answer

    Hours of futzing around and then right after posting, I find OnNewIntent()...
    Thanks for reading! I've got what I need.

Sign In or Register to comment.