Junior — Middle
What methods can be used to transfer information between components of an Android application using Intent?.
sobes.tech AI
Answer from AI
In Android, the following methods can be used to pass information between components using Intent:
- Extras — adding data to Intent using
putExtra()methods. Allows passing primitive types, strings, serializable objects, etc.
Intent intent = new Intent(this, AnotherActivity.class);
intent.putExtra("key", "value");
startActivity(intent);
-
URI and Data — you can set a URI using
setData()to pass a link or another resource. -
Action and categories — used to define the type of action the component should perform.
-
Serializable and Parcelable objects — for passing complex objects through Intent, the class must implement
SerializableorParcelableinterface. -
Flags — to control the behavior of activity launch.
Thus, the main way to pass information is by adding data to Intent through extras, which makes it easy to pass necessary parameters between components.