android - java - access incremented static variable from another class -
i have static variable , updating it's value in class. when access variable class , shows unupdated value.
class a
public static int postid = 1; public static string creator() { string message = "post id="+postid; return message; } void updatepostid() { postid++; //this function being called each 10 seconds } @override public void start() { handler.post(show); } handler handler = new handler(); private final runnable show = new runnable(){ public void run(){ ... updatepostid(); handler.postdelayed(this, 10000); } };
class b
string message = a.creator(); //this prints postid 1 time
i need global variable can access each class , update value. waiting (i using android service)
this tested code .
public class { public static int id = 0; public static int increment(){ return a.id++; } } public class b { public static void main(string[] args) { (int = 0; < 5; i++) { system.out.println(a.increment()); } } }
Comments
Post a Comment