{"action":"opened","issue":{"url":"https://api.github.com/repos/doridori/Pilot/issues/8","labels_url":"https://api.github.com/repos/doridori/Pilot/issues/8/labels{/name}","comments_url":"https://api.github.com/repos/doridori/Pilot/issues/8/comments","events_url":"https://api.github.com/repos/doridori/Pilot/issues/8/events","html_url":"https://github.com/doridori/Pilot/issues/8","id":109328418,"number":8,"title":"Best way to retain PilotStack in RootActivity","user":{"login":"doridori","id":1244430,"avatar_url":"https://avatars.githubusercontent.com/u/1244430?v=3","gravatar_id":"","url":"https://api.github.com/users/doridori","html_url":"https://github.com/doridori","followers_url":"https://api.github.com/users/doridori/followers","following_url":"https://api.github.com/users/doridori/following{/other_user}","gists_url":"https://api.github.com/users/doridori/gists{/gist_id}","starred_url":"https://api.github.com/users/doridori/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/doridori/subscriptions","organizations_url":"https://api.github.com/users/doridori/orgs","repos_url":"https://api.github.com/users/doridori/repos","events_url":"https://api.github.com/users/doridori/events{/privacy}","received_events_url":"https://api.github.com/users/doridori/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-10-01T15:49:51Z","updated_at":"2015-10-01T15:49:51Z","closed_at":null,"body":"Currently the PilotStack is persisted via \r\n\r\n```java\r\n@Override\r\n    public final PilotStack onRetainCustomNonConfigurationInstance()\r\n    {\r\n        return mPilotStack;\r\n    }\r\n```\r\n\r\nand reinstated via \r\n\r\n```java\r\n    /**\r\n     * This grabs the state stack that survives config changes (but not process death which requires\r\n     * serializing or parceling the stack). The {@link PilotStack} could live in an app wide Singleton\r\n     * but its nice to have it linked to an Activity as it can be GCd when the activity is killed.\r\n     *\r\n     * @return true if the application is starting fresh\r\n     */\r\n    private boolean ensureStateStackPresent()\r\n    {\r\n        PilotStack persistedPilotStack = (PilotStack) getLastCustomNonConfigurationInstance();\r\n        boolean freshStart = persistedPilotStack == null;\r\n\r\n        if(freshStart)\r\n            mPilotStack = new PilotStack();\r\n        else\r\n            mPilotStack = persistedPilotStack;\r\n\r\n        return freshStart;\r\n    }\r\n```\r\n\r\nwhich allows it to live through config changes. \r\n\r\nHowever, I imagine this will still work if the Activity is killed in the background (can test with dev settings) but prob not if the process is killed in the background due to mem constraints. However in this case we may need to persist the stack in savedState bundle anyhow (or parcel).\r\n\r\nIf find that when activity killed in bg object is not retained could actually make stack `static` as long as its cleaned up properly when Activity is actually destroyed for good.\r\n\r\nIf doing this will need to clear stack down in onDestory (if finishing = true) AND this needs to result in some cleanup lifecycle method being called in all frames (popped will suffice) POP all!"}}