While a user moves around my app I collect key events in a list. When the user quits the app I want to:
- write that list to a file; and
- upload that file to the cloud for analysis on the backend
I put everything in a function and unit-tested, and it works fine so long as the app is still active. But:
- calling the function from the MainActivity onStop() doesn't upload the file to the cloud (it is written to the device successfully)
- ditto onPause()
- I tried to send a completableDeferred to the function and .await for it, but that didn't help either (I used a coroutine scope initiated by MainActivity).
I've heard before the edict "Though shalt not mess with the lifecycle events", so I guess this is a confirmation...
How do you suggest I accomplish this (upload the file to the cloud when the user quits the app)? It doesn't need to be immediate, it just needs to happen eventually.
Thank you!
WorkManager(probably periodically).