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

html - Difficulties with background-image property -

visual studio code - What does the isShellCommand property actually do and how should you use it? -

ios - Segue not passing data between ViewControllers -