Câu hỏi phỏng vấn Android
Câu hỏi

How to declare Global variables in Android?

Câu trả lời

Here's how to declare global variables in Android:

Declaring Global Variables

  1. Create a custom Application class

    • Create a new class that extends android.app.Application.
    • Declare your global variables as instance variables in this class.
  2. Override the onCreate() method

    • Override the onCreate() method and initialize your global variables.
  3. Register the custom Application class in the manifest

    • Open the AndroidManifest.xml file.
    • Find the <application> tag.
    • Add the android:name attribute and set it to the fully qualified name of your custom Application class.

Example:

java Copy
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

middle

Gợi ý câu hỏi phỏng vấn

senior

What is Doze? What about App Standby?

middle

When to use Android's ArrayMap instead of a HashMap ?

middle

What is the actual differences between a Activity Context and Application Context?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào