java - android app stop variable from resetting - lifecycle -
i have app has few screens. main screen automatically opens "new" screen if it's first time user opens app. set boolean variable (on main screen) keeping track of this.
the intention if user goes main screen, code opens "new" screen can skipped.
the problem variable keeps getting reset on oncreate. so, added code use sharedpreferences.
this works; however, want clear variable when app exits. (i want "new" screen open every time app opens first time). so, looking @ lifecycle tried both onstop , ondestory. sharedpreferences cleared but... not when app exited; when "new" screen appears.
am looking @ lifecycle wrong? there sort of global variable can declare lives while app open?
this functionality requirement, cannot change it.
you should use onsaveinstancestate , onrestoreinstancestate, keep boolean alive if activity calls oncreate not if exit , come later.
see answer implementation: saving android activity state using save instance state
Comments
Post a Comment