How to save a user's state when app unexpectedly closes

I have a feature in my app where a user must visit an external url, then return to page. In android, the app stays open and when returned to, it should still be on the same page as it was when the user left. If they had a field filled out, it should still be there. But I have noticed in appgyver app, it is not. When I try to return to the app after leaving it open in background, it returns to the app launch screen and then the initial page as though it was just opened. This is the built apk installed on my android device.

Any java or kotlin app I have ever built in android studio has never required any custom code to be able to reopen to same page with every input the same as when user opened another app from within the app. But I am new to react native and to appgyver. Now that I am aware of this, I need to figure out a way to allow a user to reopen app and have the state be the same as when they left by opening another app from within the app. After all, the app does not close. It remains open, just minimized.

I am considering making a local storage key “last_page” with the value as some value representing the pages in the app, then, when app is opened, checking to see if there is a value there and, if so, sending user to that page, or perhaps make an alert asking them if they would like to pick up where they left off. But in this case I would have to write a new value on every page load, and if they intentionally close the app, delete the value before closing. And in the case of them being in the middle of filling out a form, uploading an image, or something else, I would have to get pretty fancy with the stored values and other logic.

Does anybody else know an easier (or, I should say, more light-weight), way of accomplishing this?

Thanks for any help. I will try to help others with things I have learned when I have the time, as I always try to do.

Yes, put a Receive Event node on your first or initial page called 'Page will unmount". This will trigger right before the app closes. Then you can put logic in there to save your data.


1 Like

Does ‘Page will unmount’ work in the previewer? Mine isnt triggering my unmount event.

1 Like

no I never got it to work

what if the app does not close from the initial page? And what if the initial page has already been dismissed?

to close loop on this, ended up solving this inversely by using ‘Page Mount’ and client-side storage. So I save the data into a variable then client-side storage. When the app launches, it checks the client-side storage, if the check doesn’t return null, the app logic I need runs.