Android Question Static Variable

Mark.S

Member
Licensed User
How do you create a static variable within a class, so that it retains it's value between calls?
the only way I can see this being done is by using one of the .tag properties of a view created within the class.
 

Cableguy

Expert
Licensed User
Longtime User
Search for "Constant"

If I'm not mistaken, you can use like

Private const myvar = 5 as int
 
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
How do you create a static variable within a class, so that it retains it's value between calls?
the only way I can see this being done is by using one of the .tag properties of a view created within the class.
When you say "between calls" - do you mean references to the variable in the same instance of the class? Or do you mean across different instances of the class?

For the former, class member variables act the same way as variables declared in an Activity - ie: as long as the class instance is "alive", the variable will retain whatever value was assigned to it. The only way to maintain a variable across instances of a class is to declare it with an initial value. You can't change a variable value in one instance of a class & then reference that value in another instance.

Or maybe I'm misunderstanding your question...

- Colin.
 
Upvote 0
Top