• Latest Code...

    Featured Post

    Implementing Hilt in a Kotlin Android Jetpack Compose Project with MVVM Architecture

     In modern Android development, maintaining a scalable codebase can be challenging, especially when it comes to dependency management. Hilt,...

    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 {

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


    Happy Coding!!!


    Contact Form

    Name

    Email *

    Message *