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.

[[{"type":"media","view_mode":"media_original","fid":"25","attributes":{"alt":"","class":"media-image","height":"137","width":"382"}}]]

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

[[{"type":"media","view_mode":"media_original","fid":"26","attributes":{"alt":"","class":"media-image","height":"439","width":"587"}}]]

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

[[{"type":"media","view_mode":"media_original","fid":"27","attributes":{"alt":"","class":"media-image","height":"437","width":"603"}}]]

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.