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 activitys.

step 1:

extend activitys 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

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -