Short answer: call moveTaskToBack(true)
on your Activity
instead of System.exit()
. This will hide your application until the user wants to use it again.
The longer answer starts with another question: why do you want to kill your application?
The Android OS handles memory management and processes and so on so my advice is just let Android worry about this for you. If the user wants to leave your application they can press the Home button and your application will effectively disappear. If the phone needs more memory later the OS will terminate your application then.
As long as you're responding to lifecycle events appropriately, neither you nor the user needs to care if your application is still running or not.
So if you want to hide your application call moveTaskToBack()
and let Android decide when to kill it.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…