How to declare global variables in Android?

Technology CommunityCategory: AndroidHow to declare global variables in Android?
VietMX Staff asked 4 years ago

The way to do this is to create your own subclass of android.app.Application, and then specify that class in the application tag in your manifest.

public class MyApp extends Application {
  String foo;
}

In the AndroidManifest.xml add android:name

<application android:name=".MyApp" 
       android:icon="@drawable/icon" 
       android:label="@string/app_name">