How do I pass data between Activities in Android application?
How do I pass data between Activities in Android application?
Here's how you can pass data between Activities in an Android application:
putExtra()
method. For example:Intent intent = new Intent(this, ReceivingActivity.class);
intent.putExtra("key", "Value to pass");
startActivity(intent);
getIntent()
and getStringExtra()
(or the appropriate method based on the data type). For example:String value = getIntent().getStringExtra("key");
putString()
, putInt()
, etc. For example:Bundle bundle = new Bundle();
bundle.putString("key", "Value to pass");
intent.putExtras(bundle);
getBundle()
and getString()
(or the appropriate method based on the data type). For example:Bundle bundle = getIntent().getExtras();
String value = bundle.getString("key");
SharedPreferences sharedPreferences = getSharedPreferences("MyPrefs", MODE_PRIVATE);
SharedPreferences.Ed...
junior
Gợi ý câu hỏi phỏng vấn
Chưa có bình luận nào