Best way around android device sleeping and losing info on local devices

I am trying to find a tidy way around the mqtt plugin losing info on non MQTT devices on disconnect and reconnect.

For example - I have a complex device (Honeywell resideo profile editor). You can be 2 or 3 pages down into editing - get distracted - the android device goes to sleep and disconnects. When it comes back up - you are still on the same page but all the editing/edited values are gone - because they were in a local device - built when you first started editing. I can’t get the info back from the remote MQTT server because it is not aware of the ‘in progress edits’.

The best I could think of is go back to the home page and get the original info from MQTT, losing any edits in the process- probably what I will end up doing. I also need to work out a way of popping to the root page on disconnect.

Has anyone else had to handle this and come up with a neat solution?

You did not say which type of phone you have or what level of Android it is on. But I also had a similar issue with a Direct TV connection (connected via IP rather than IR).

The solution I did was to disable battery optimization for the Home Remote application. Go to the Android setup, Apps, Home Remote, Battery, then click on “Unrestricted” (sometimes called “Unoptimized” or other similar terms). On my S22U, the other choices I don’t want are “Restricted” nor “Optimized”.

Thanks - I will have a play with that.
It may not work in my setup fully because I will be passing this app to several, non technical users and they need very simple method to load and run it!

In the meantime I have found a workaround using scenes. SOLVED ish.

Set a global variable in the plugin when I start editing local devices.
In onconnect, if that variable is true I set a local device property onconnected to true.
A scene watches this variable and if it becomes true - it calls app poptorootpage.

The user sees the app come back up (after disconnect) on the page where he was UNLESS he had been editing local devices, in which case it appears to go back to the start of his editing session.

I had thought about saving local device(s) in global variables but that was a messy task and also prone to issues like - how long do you keep the data? Using the poptoroot idea means that if you allow your phone to go to sleep during an edit, it discards the edit.

I keep finding new twiddles in THR and now I know about scenes I’ll find other uses for them.