Forum Xamarin.Forms

Firebase onnotificationopened restarts the app?

devxusdevxus Member ✭✭
edited August 2019 in Xamarin.Forms

I am using Plugin.FirebasePushNotification to recieve push notifications in my xamarin cross platform application.

In android which i started to test first....
If if recieve a notification and app in foreground --> on tapping the notification the app's previous state of the app is retained and you see the last opened tabpage.

But if the app is in background and I click on the notification .... the onstart method is executed and app restarts to the login screen and the previous state of the app is lost.

The app works fine and fires onresume if it is in background and if we click on icon from home screen etc.

Why onresume is not fired and onstart is fired when my app is in background and I click on the notification to open.

I am new to xamarn so is this something very silly I am missing?

UPDATE: I just found that when mainlauncher=true is splashactivity then this happens.If mainlauncher=true for mainactivity then onnotificationopened is followed by onresume and app resumes previous state and does not start over from login.

what should I do ?

Best Answer


  • devxusdevxus Member ✭✭
    edited August 2019

    I am sorry I am new to xamarin so a little lost and not able to follow.

    I do not need the contents of the notification since I refresh the screen for fresh data onresume on recieving notification.
    So do i need pending intent?
    Also, the app resumes fine to the previous state if I put it in the background and return to it by clicking the app icon from home screen OR if I recieve the notification when app is in the foreground and then I click on the notification the onresume is fired and loads the respective tab page.

    I have the onnotificationopened code in app.cs in my xamarin cross platform porject.

    [Activity(Label = "Supervisor", MainLauncher =true, Theme ="@style/ThemeSplash", NoHistory =true )]
    public class SplashActivity : AppCompatActivity
    protected override void OnCreate(Bundle savedInstanceState)
    var mainIntent = new Intent(Application.Context, typeof(MainActivity));
    if (Intent.Extras != null)

    Below is Mainactivity:

    [Activity(Icon = "@drawable/Logo", Label = "Supervisor", Name = "xxx", Theme = "@style/AppTheme",LaunchMode =LaunchMode.SingleTop, MainLauncher = false, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
    public class MainActivity : FormsAppCompatActivity
        internal static MainActivity Instance { get; private set; }
      protected override void OnCreate(Bundle bundle)
                ToolbarResource = Resource.Layout.Toolbar;
                TabLayoutResource = Resource.Layout.Tabbar;
                Xamarin.Forms.Forms.Init(this, bundle);
                Instance = this;
                LoadApplication(new App());
                FirebasePushNotificationManager.ProcessIntent(this, Intent);
                FirebasePushNotificationManager.Color = Android.Graphics.Color.Rgb(150, 189, 13);
                FirebasePushNotificationManager.IconResource = Resource.Drawable.NotificationIcon;
                FirebasePushNotificationManager.NotificationActivityFlags = ActivityFlags.ClearTop | ActivityFlags.SingleTop;      
        protected override void OnNewIntent(Intent intent)
                FirebasePushNotificationManager.ProcessIntent(this, intent);
  • devxusdevxus Member ✭✭

    I managed to make the mainactivity as my mainlauncher with the theme of splash activity set and oncreate of the mainacitivity I change the theme back to the app theme .

    Now the push notifications retain the state when got to foreground from background.

    Thank you for your reply.
    But I do want to know what you meant in your answer.

Sign In or Register to comment.