GCWizard
GCWizard copied to clipboard
Store inputs when closing page
[from @AndyPuma]
Avoid removing all input when you close a page.
I really would appreciate this feature. But I want to avoid to add code like this to every single widget:
@override
void dispose() {
saveInput(textField1);
saveInput(optionSwitch1);
...
super.dispose();
}
A more centralized function would be great, which does it on its own. Furthermore keep in mind, that storing into a database is an asynchronous operation, which has to be handled properly if chosen this approach!
I believe this would be a great support for every user. However, a more centralized function which hooks into the android system is a complex issue.
An idea came to me under the shower.
Every tool/window we open is internally pushed to a stack of open windows. On closing, this window is removed from the stack and deleted including all settings, etc.
What if we get access to this internal stack mechanism? In that case we could try following:
- Open widget A and push it to the stack as normal.
- In parallel storing A into a global list.
- When closing A, it will be popped from the stack as normal, but still exists in the list
- When coming back to A, instead of creating a new instance of A by the internal mechanism, we first check the list if an old instance of A still exists. If not, go ahead with step 1, otherwise take the stored instance from list.
I have absolutely no idea if this could work. First: Can we hook into the stack mechanism and manipulate it? And second, what are the side effects (we often fought with very strange effects on single input widgets because of no-released internal pointers... May be that keeping an entire window open could be extremely dangerous from that point of view. What about internal memory? When never closing the app, the memory usage may increase extremely.). This is surely not working when closing the app entirely, but during a session it may work. But due to memory lacks we should think about closing the windows after X days or so...