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

junior

Explain briefly all the Android application components

senior

What are best practices for storing and protecting private API keys in applications?

junior

What is View Group? How are they different from Views?

Bình luận

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

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