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

How do I pass data between Activities in Android application?

Câu trả lời

Here's how you can pass data between Activities in an Android application:

Using Intents

  1. In the sending Activity, create an Intent and put the data you want to pass using putExtra() method. For example:
Intent intent = new Intent(this, ReceivingActivity.class);
intent.putExtra("key", "Value to pass");
startActivity(intent);
  1. In the receiving Activity, retrieve the data from the Intent using getIntent() and getStringExtra() (or the appropriate method based on the data type). For example:
String value = getIntent().getStringExtra("key");

Using Bundles

  1. Create a Bundle in the sending Activity and put the data you want to pass using putString(), putInt(), etc. For example:
Bundle bundle = new Bundle();
bundle.putString("key", "Value to pass");
intent.putExtras(bundle);
  1. In the receiving Activity, retrieve the data from the Bundle using getBundle() and getString() (or the appropriate method based on the data type). For example:
Bundle bundle = getIntent().getExtras();
String value = bundle.getString("key");

Using SharedPreferences

  1. Store the data in SharedPreferences in the sending Activity. For example:
SharedPreferences sharedPreferences = getSharedPreferences("MyPrefs", MODE_PRIVATE);
SharedPreferences.Ed...
junior

junior

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

expert

What happens if the user navigates away or closes the app while I still have a reference to the Activity
the user just closed in my AsyncTask ?

senior

What is Broadcast Receiver?

senior

Explain how ArrayMap works

Bình luận

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

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