android - Best Place to Put "Auto Start" another activity code? -
my android application(application a) launches application (say application b) upon click of button.
now want implement "auto start" functionality wherein application b launched application launched. this, created checkbox , used sharedpreferences
store value of checkbox. then, in oncreate()
method of activity a, checking value of checkbox sharedpreferences
, launching application b in case value "true".
the problem:
the problem facing is, when user exits "application b" (and comes application a) oncreate()
of application getting called again , application b opens again. sets off infinite loop , @ exit of application b, user returns application , goes application b again.
i know oncreate() gets called multiple times (when change orientation, keyboard opened, activity goes background , killed system), there clean way of doing this?
to reiterate, requirement launch application b application if "auto start" checkbox checked in application a.
my suggestion use method onpause
of activity in application , set flag there "application b called". if flag set not call application b in oncreate
of activity in application , unset flag.
if application b long in foreground application might suspended system , flag reset. in such case maybe idea have flag stored in persistent storage (e.g. sharedpreferences
).
edit 1 more thing: flag should set in onpause
if activity being paused, because other application shown (this determinable, because happens in same class).
Comments
Post a Comment