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

How could you pass data between activities without Intent ?

Câu trả lời

Here are a few ways to pass data between Android activities without using an Intent:

1. Using a Singleton Class

  • Create a singleton class to hold the data you want to share between activities
  • Instantiate the singleton in each activity that needs access to the data
  • The singleton will maintain a single instance of the data that all activities can reference

2. Using a Shared Preference

  • Use SharedPreferences to store the data you want to pass between activities
  • Write the data to SharedPreferences in one activity
  • Read the data from SharedPreferences in the other activity
  • SharedPreferences provides a simple key-value store for storing small amounts of data

3. Using a Static Variable

  • Declare a static variable in a class to hold the data you want to share
  • Set the value of the static variable in one activity
  • Access the value of the static variable in the other activity
  • Static variables are accessible from anywhere in ...
middle

middle

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

middle

What is a LocalBroadcastManager ?

junior

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

senior

When to use SparseArray vs HashMap ?

Bình luận

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

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