Mystogan
Mystogan

Reputation: 577

Xamarin android - Returning from push notification won't display page content

Returning from a push-notification, my Xamarin android App won't show the content of my Page.

Reproducing:

  1. "Minimizing" the app
  2. Click a recieved push notification to open the app

The app starts as expected. However, after starting it's supposed to display my start page (a simple ContentPage with a WebView) - but nothing is shown. Debugging, I can see that my page is loaded (OnAppearing is called). Starting the app "minimized" usually works - just not when clicking from a notification!

Code for when the app recieves a notification (please tell me if other code is more relevant!):

var intent = new Intent(this, typeof(MainActivity));
intent.AddFlags(ActivityFlags.ClearTop | ActivityFlags.SingleTop);
var pendingIntent = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.UpdateCurrent);

var notificationBuilder = new Notification.Builder(this)
   .SetSmallIcon(Resource.Drawable.testicon)
   .SetContentTitle("Test")
   .SetContentText(messageBody)
   .SetAutoCancel(true)
   .SetContentIntent(pendingIntent)
   .SetVisibility(NotificationVisibility.Public)
   .SetPriority((int)Android.App.NotificationPriority.High);

var notificationManager = NotificationManager.FromContext(this);
notificationManager.Notify(0, notificationBuilder.Build());

Any help to point me in any direction is appreciated!

Upvotes: 2

Views: 505

Answers (1)

Elvis Xia - MSFT
Elvis Xia - MSFT

Reputation: 10831

The app starts as expected. However, after starting it's supposed to display my start page (a simple ContentPage with a WebView) - but nothing is shown.

If you need your Forms app to start from the beginning, you need to comment out/remove intent.AddFlags(ActivityFlags.ClearTop | ActivityFlags.SingleTop);. This flag will restore the existing running app instead of running a new instance of your app.

Upvotes: 1

Related Questions