The problem
First problem: app press Back button twice to desktop, and then return app data is not empty
- I have a global singleton in my project that’s saving data and I find that every time I hit the Back key and go Back in the App the data is incrementing and it doesn’t matter if I clean up all the methods in its life cycle, okay? So after browsing data search, get such an answer!
Read the following sentence carefully to understand what it means
- In addition, pressing the back key in the activity actually calls the Finish method, and the application exits. Although the application has exited, the process has not been killed. In Android, an application runs in a separate virtual machine instance, so static objects in a class remain in their runtime state when the application is restarted. Be careful to reset these states in an appropriate place.
- Static variables or global singletons are stored in the process and cannot be destroyed immediately, retaining the current value. To solve this problem, simply reassign the static variable in the onCreate method.
- When I save the data in the singleton, I don’t reload the new collection but I use the old one so the data keeps getting messed up
- If the singleton mode is used to store data, it should be called
The data container is empty
orTo the new
Second problem: App presses the home button to the desktop, and then returns to app without restarting app
-
Problem: When the home button hits the desktop and you return to the app, the app opens again, but the original interface is still there, just a layer over the original interface. Androidmanifest.xml, the main activity.
Android: launchMode=""
Share with you
I want to work my way up
Fly forward on the blades at the highest point
Let the wind blow dry tears and sweat
I want to work my way up
Waiting for the sun to watch its face
Little days have big dreams
I have my day
Let the wind blow dry tears and sweat
One day I will have my day