Saga continues to run even if android onDestroy was called - android

I don't understand why my rootSaga continues to run after my android onDestroy was called.
When using the app if I do config changes like font-size, screen rotation etc ...
android onDestroy will be called (I still see app in recent apps which is also weird).
The app will open but everything will be stuck because my rootSaga is not being restarted and will continue from the place where it was before

Related

OnCreate is called multiply when app is started from Play Store App first and then from home screen

It occurred to me that under some circumstances our app seems to be restarted from scratch after being backgrounded. I managed to track to issue down to MainActivity.OnCreate being called multiply under the following circumstances
App is installed from APK and then ran from the installer, after backgrounding the app and starting it from the home screen it's reset to scratch
This behavior persists until the app is killed and then restarted from the home screen
App is run from Google Play app, after backgrounding the app and starting it from the home screen it's reset to scratch
If the app is backgrounded and then started from Play Store it's started correctly
App is run from home screen, after backgrounding the app and starting it from Google Play it's reset to scratch
When the app is foregrounded from the same launcher it has been started initially, OnCreate is not called again. There is at least one question reporting a similar behavior, unfortunately there is no answer providing a solution for the behavior.
When MainActivity.OnCreate is called, the instance of MainActivity seems to be a different instance than the initial one, since private members that are set in OnCreate are null when I'm trying to log them, anyway, the application context does not seem to be recreated from scratch, because AppCenter seems to be initialized right away on the second run, Xamarin.Forms starts up way quicker and static variables keep their values.
Is there any way to prevent this behavior and just keep a single instance of MainActivity active?
Congratulations! You've been bit by a long-standing, nasty Android bug which has been around since the dawn of time and is still broken, even though countless issues have been opened about it and the behaviour is reproducible and well-documented.
See the following:
https://issuetracker.google.com/issues/36907463
https://issuetracker.google.com/issues/36941942
https://issuetracker.google.com/issues/64108432
Re-launch of Activity on Home button, but...only the first time
App restarts rather than resumes
In September 2019, one of these issues was marked "fixed" with this comment:
Thanks for reporting this issue. The issue has been fixed and it will
become available in a future Android release.
So hopefully we will no longer be seeing this in Android Z ;-)
There is a workaround documented in my answer to
Re-launch of Activity on Home button, but...only the first time
in your android manifest set on the activity tag
android:launchMode="singleTop"
It will have consequences on how you handle notifications, and in some cases onActivityResult

Wrong stack behavior on first application run (before restart)

I am trying to understand some behavior of the android apps, now that I faced the following issue :
After device restart my app launches by default, but with one issue : If I put it in the background, and I try to resume it from HOME launcher, it restarts from splash
Weird is that this happens ONLY & ONLY after the device it was installed on, is restarted ! To break this behavior I have to kill the app and launch it again. From that point it works as expected -> If in background, using launcher icon restore the app state
Looking a bit in the logs from lifecycles of the activities in cause, I noticed that the flow is pretty much the same ! With the difference that after onResume of last active activity, the SplashScreen gets launched (this being LAUNCHER activity)
Now, I've seen that this might be already an issue reported to Google, even multiple times, but .. If I cannot fix or workaround it, I am at least trying to understand the flow of what happens on these cases.
Edit:
Seems to be related to FLAG_ACTIVITY_NEW_TASK set in the Receiver, but.. then again I cannot start the app after boot is completed without this flag! Feels like a cycle I can't get out of..

Force full app restart in order to refresh packages in Cordova

I'm looking to restart the app completely from the app itself( really restart the app(full load) and not just rerender the index).
This needs to happen because some packages also need to re-initialize and this can only be done when fully restarting the app.
I've tried this package https://www.npmjs.com/package/cordova-plugin-exit which doesn't seem to work.
And navigator.app.exitapp() also isn't what i'm looking for or does this exactly do what I want it to do?
Is the best solution to create a cordova wrapper plugin which does this for android and IOS differently?
You can do this on Android with the restart() method of cordova-diagnostic-plugin:
// Warm restart
cordova.plugins.diagnostic.restart(null, false);
// Cold restart
cordova.plugins.diagnostic.restart(null, true);
By default, a "warm" restart will be performed in which the main Cordova activity is immediately restarted, causing the Webview instance to be recreated.
However, if the cold parameter is set to true, then the application will be "cold" restarted, meaning a system exit will be performed, causing the entire application to be restarted. This is useful if you want to fully reset the native application state but will cause the application to briefly disappear and re-appear.
Note: There is no successCallback() since if the operation is successful, the application will restart immediately before any success callback can be applied.
It is not possible to programmatically restart an app on iOS; at least doing so will likely get your app rejected from the App Store.

Keep app alive when in background?

What code is required to keep an app live when it is "pushed" to the background?
My app USED to behave this way. If a user multitasked or hit home, my app would minimise, and they could later return to it. Now, and I have no idea what change I made to cause this, my app is closed by the Android system whenever it is minimised.
I have checked memory, and it doesn't seem to be an issue. My app is actually using LESS memory now than previously.
When the app is minimised and closed, OnPause and OnStop are being called for the current activity, but onSaveInstanceState is not.
SOLVED: It was caused by android:noHistory="true" in my manafest

Android: App screenshot preview in task list is blank?

In Android when you hold down the home button you can bring up a task list of your recent apps. And each "card" in the task list should have a preview of the app. However, this time I opened the task list and the previews were blank (except for the app title).
I had the phone Settings in the task list and every time I would tap on the task and try to open it in would close immediately.
I also had this app I was developing and when I tapped on the task to open the app my RecyclerView wasn't showing anything, when it should be.
I also was playing AngryBirds 2, so was it that Android had silently killed those apps for memory? If so, does onCreate() of the killed apps get called again when this happens?
Edit: I just noticed if you close an app too quickly when it's transitioning to an Activity you can get a blank preview.
Edit 2: So to answer my question, after referencing the Activity lifecycle diagram this is what I found. When another application needs memory, the app's process will be killed and when the user navigates back to the app, onCreate() will be called again. However, that doesn't explain why I couldn't reopen the Settings. And I have no idea how to reproduce this weird behavior!
Ok after some debugging, I found out that Android did indeed kill my app because it needed memory. When you resume to your app however, onCreate will be called with a savedInstanceState that is NOT null. I had some logic that required savedInstanceState to be null and therefore my RecyclerView wasn't populated.
To recreate this scenario of Android killing my app I had to open a ton of apps lol. Is there way I can reproduce Android killing my app without opening all those apps? Hm...

Categories

Resources