What happens when all activities of an application finishes?

前端 未结 4 1536
南方客
南方客 2020-12-28 08:24

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 App

4条回答
  •  猫巷女王i
    2020-12-28 08:50

    for your Update:

    How can I clear the application constants on exit of the application(Back press of the HomeActivity)?
    

    Override onBackPressed inside your HomeActivity and before call super.onBackPressed() clear all the variable. If you have a setter for a String located inside your Application subclass:

    @Override
    public void onBackPressed() {
        getApplication().setMyString(null);
        super.onBackPressed();
    }
    

    if you have plenty states to clear you can write a method wich reset all the fields and call it:

    @Override
    public void onBackPressed() {
        getApplication().clearAllMyFields();
        super.onBackPressed();
    }
    

    Of course those field have not to be marked as final or static final

提交回复
热议问题