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

middle

What is the difference between Adapter and Loader in Android?

middle

Explain how HashMap works

middle

What is the difference between onCreate() and onCreateView() lifecycle methods in Fragment ?

Bình luận

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

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