Scenario:
I've four activities in my Android Application, lets say A, B, C and D. There is one Constants.java
class in the app which extends Application
class in order to maintain global application state. The Constants class have all the constants variables of the app. The activity flow is like this A-->B-->C-->D
. When back button is being pressed from Activity A, I'm calling finish() method which will finishes the activity A and closes the application. After that if I'm opening the app from all apps, there is a variable in Constants.java
whose value persists from the last launch. The same thing is not happening when I'm doing System.exit(10)
followed by Process.killProcess(Process.myPid())
from activity A(on back pressed).
Questions:
- Will finishing all activities by calling finish() of each activity will close the Application(Its process)?
- How the value of a variable persists even if its all activities are finished(closed)?
- Is it fair to call
System.exit(10)
followed byProcess.killProcess(Process.myPid())
for exiting the application?
Update:
How can I clear the application constants on exit of the application(Back press of the HomeActivity)?