Android using static boolean as flag to determine if activity is visible -
i wanted hear other opinions using following method determine other activities or services if activity visible: method using static boolean
s flags, values depends of activity life-cycle. implemented solution , seems work alright. have doubts whether reliable solution, because, understand, activity life-cycle contained inside of instance of activity class, static methods or fields applies instances. activity, visibility status needs determined, i've used singletask
launch mode, there shouldn't more 1 instance. in mind, safe assume static boolean 100% represent actual status of activity?
well, sure can use static boolean flags. however, if have more options true/false, recommend use enum
instead.
if application has more 2 activities, using booleans leads hard maintenance.
so clear code use enum flags like:
public enum eactivitystate{ unknown, visible, not_visible, launched, // .... }
after can use:
private eactivitystate mactivitystate = eactivitystate.unknown; .... if(eactivitystate.launched == mactivitystate ){ // }
Comments
Post a Comment