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:

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

expert

When to use AIDL vs Messenger Queue?

senior

Why to consider FlatBuffers over JSON ?

middle

What is an Android PendingIntent ?

Bình luận

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

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