FirebasePushNotificationPlugin icon indicating copy to clipboard operation
FirebasePushNotificationPlugin copied to clipboard

Prevent restart when app is running

Open kerberosargos opened this issue 4 years ago • 4 comments

Hello I would like to consult about a issue. When I am clicking to the received notification from Android statusbar when my application is running on foreground or background. Application does not appear. it restart itself instead of appear. I would like to just appear when my app is running. is there any way to achieve that? Thank you in advance.

kerberosargos avatar Aug 06 '20 15:08 kerberosargos

I have the same problem

FelipeFC avatar Sep 04 '20 14:09 FelipeFC

Hi all, that is something I resolved with this code in SplashScreen if you have it,

protected override void OnCreate(Bundle savedInstanceState) {

  base.OnCreate(savedInstanceState);
  var mainIntent = new Intent(Application.Context, typeof(MainActivity));
  if (Intent.Extras != null)
  {
     mainIntent.PutExtras(Intent.Extras);
  }
  if (someFlag)
  {
      // to avoid restart the app
      mainIntent.SetFlags(ActivityFlags.SingleTop); 
  }
  else
  {
      // to restart the app
      mainIntent.SetFlags(ActivityFlags.ClearTop);
  }

StartActivity(mainIntent);

}

Regards

mimunoz avatar Sep 04 '20 14:09 mimunoz

Thank you very much, I made this change and it worked.

 public class SplashActivity : Activity
 {
  protected override void OnCreate(Bundle savedInstanceState)
  {
   base.OnCreate(savedInstanceState);

   var mainIntent = new Intent(Application.Context, typeof(MainActivity));   
   if (Intent.Extras != null)
   {
    mainIntent.PutExtras(Intent.Extras);
   }
   mainIntent.SetFlags(ActivityFlags.SingleTop | ActivityFlags.ClearTop);

   StartActivity(mainIntent);
  }
 }

FelipeFC avatar Sep 04 '20 15:09 FelipeFC

Hi all, that is something I resolved with this code in SplashScreen if you have it,

protected override void OnCreate(Bundle savedInstanceState) {

  base.OnCreate(savedInstanceState);
  var mainIntent = new Intent(Application.Context, typeof(MainActivity));
  if (Intent.Extras != null)
  {
     mainIntent.PutExtras(Intent.Extras);
  }
  if (someFlag)
  {
      // to avoid restart the app
      mainIntent.SetFlags(ActivityFlags.SingleTop); 
  }
  else
  {
      // to restart the app
      mainIntent.SetFlags(ActivityFlags.ClearTop);
  }

StartActivity(mainIntent);

}

Regards

Thank you very much it is working for me too.

kerberosargos avatar Sep 07 '20 10:09 kerberosargos