java - How to access the same variable between Activities in Android -
i'm wondering how go accessing same int
variable between activity
classes in android app. situation have variable represents number of points , i've placed in own class , want value same between every activity
uses it.
when user gets point, increases 1 let's user gets 12 points, want same throughout activity
s.
step 1:
extend activity
s common baseactivity
class.
step 2:
put int
variable in baseactivity
, add protected
, static
qualifiers int
variable:
public class baseactivity extends activity{ .... .... protected static int points; .... .... }
now can access points
variable in every activity
, have same value.
there no need use singleton here other answers suggesting. simpler have common static
variable. programming 101.
try this. work.
Comments
Post a Comment