How to declare Global variables in Android?
How to declare Global variables in Android?
Here's how to declare global variables in Android:
Create a custom Application class
android.app.Application.Override the onCreate() method
onCreate() method and initialize your global variables.Register the custom Application class in the manifest
AndroidManifest.xml file.<application> tag.android:name attribute and set it to the fully qualified name of your custom Application class.Example:
public class MyApplication extends Application {
public static final String API_KEY = "your_api_key";
public static int counter = 0;
@Override
public void onCreate() {
super.onCreate();
// Initialize global var...
middle