Is there a way to do a task when an app is placed in the background?

I made a text editor for Android. I made a small list, brought up Firefox, and then when I went back to the editor what I typed was gone. Is there a way to make it so that when the editor is placed in the background I can save the contents of the textbox, and when it's back in the foreground I can load the file back into the textbox?


Use the ActivityChanged event from the tools extension

If state = pause
Then save your data to TinyDB

If state = resume
Then get the data again from TinyDB


1 Like

Or this:

save it with TinyDB in the ActivityLifecycle.Stop event and get TinyDB in the ActivityLifecycle.Resume event.

1 Like

OK, I used the Tools Extension checking on the state. Works great, thank you.
Seems odd to me that the example uses the math compare function with text, but I guess the math = and Compare Texts = works the same.