You are here

Android - Global variables

If your Android application contains two or more activities you may need to store global variables that can be accessed from any activity.    

Create a new class inherited from Application class and create your global variables in it.

Now we have to specify the name of the class in AndroidManifest.xml file:

We can reference to the global variables in the code of Activities as follows:

We can also create methods in MyApplication class, they can be accessed the same way.

Add new comment

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
Refresh Type the characters you see in this picture. Type the characters you see in the picture; if you can't read them, submit the form and a new image will be generated. Not case sensitive.  Switch to audio verification.