0

After implementing OneSignal library into my Xamarin project, and configuring it from their documentation everything works fine, but when my application is in the background (minimized) and I click on the notification it restarts my App from the start (showing splash screen, Lottie animation, initialize all libraries again, creating new App(), etc)

Is this default behavior or it should bring my app from the background to focus instead ?

And this way I cant catch data send from notification in restarted app, but I do catch OnNotificationOpened in the background app but then it closes and restarts.

It is Android startup project

Matija Gluhak
  • 260
  • 2
  • 13
  • It is app code that controls what happens when app goes to background, then resumes from background. Read about android app lifecycle methods. Find an explanation of the code you need to add to remember what the app was doing when it goes into background, and to restore that state when app returns to foreground. Then look in Xamarin Android project for App or Activity OnPause and OnResume methods. – ToolmakerSteve Nov 06 '21 at 18:03
  • @ToolmakerSteve tnx for explaining, what is strange to me is that my background app handle event from push notification OnNotificationOpened, and when it exit this method application is started again .. i put breakpoints on OnResume and OnPause and they didn't fire at least not OnResume. If i get you correctly when i put my app in background and OnPause is executed i need to do something so when next time app starts it can restore state or something like that ? from Bundle ? – Matija Gluhak Nov 06 '21 at 18:39
  • https://learn.microsoft.com/en-us/xamarin/android/app-fundamentals/activity-lifecycle/saving-state - maybe instead of putting code in OnPause, you can put code in `public override void OnSaveInstanceState`, to create a Bundle that you examine when app is created again. But that doesn't happen until OnStop, so not sure if it does what you need. – ToolmakerSteve Nov 06 '21 at 18:45
  • @ToolmakerSteve yes i read this docs https://learn.microsoft.com/en-us/xamarin/android/app-fundamentals/activity-lifecycle/ and what is bothering me or i don't understand is why if my handler from background app is fired why is my app closing and restarting new one and doesn't bring one from background to focus – Matija Gluhak Nov 06 '21 at 19:06
  • @ToolmakerSteve hey m8 .. tnx for helping me out, i just found out if i remove my splash screen as mainlauncher than it doesn't restart the app, you got any idea why is this happening ? – Matija Gluhak Nov 06 '21 at 20:34
  • Are you testing with VS debugger attached? If so, that will interfere with restart - when debugger sees the app "die", it disconnects in a way that prevents restart. So after downloading from VS, start app from home icon, then minimize it, see if it can be restarted. – ToolmakerSteve Nov 06 '21 at 21:07
  • 1
    https://stackoverflow.com/a/40551574/199364 – ToolmakerSteve Nov 06 '21 at 21:12
  • 1
    well i rebuild all splash activity so my mainactivity is launcher then on OnCreate i start new splash activity and after animation ends i start main activity again but with flag that my app has been initialize so i skip creating splash activity again :) .. its kinda workaround but its working – Matija Gluhak Nov 06 '21 at 21:33

0 Answers0