• Latest Code...

    How to declare global variables in Android?

    Sometimes you have need define or declare most of the variable globally access, in such senario you have define or declare global variable like this which is simple, sooniln define on stackoverflow very simple way:

    class MyApp extends Application {

      private String myState;

      public String getState(){
        return myState;
      public void setState(String s){
        myState = s;

    Now to you have to access above defined variable before you have setStatus.

    class Blah extends Activity {

      public void onCreate(Bundle b){
        MyApp appState = ((MyApp)getApplicationContext());
        String state = appState.getState();

    Happy Coding!!!

    No comments:

    Post a Comment


    Most recent Elastic Search tutorials for beginner, intermediate and advance level developer, Yubraj Pokharel, in CodingWorkspace