You are here

Android - Global variables

Error message

The spam filter installed on this site is currently unavailable. Per site policy, we are unable to accept new submissions until that problem is resolved. Please try resubmitting the form in a couple of minutes.

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.