Junior — Middle
Could you explain what is meant by the term Intent in the context of Android app development?
sobes.tech AI
Answer from AI
In Android, an Intent is an object used to communicate between components of an application (Activity, Service, BroadcastReceiver). It describes an intention to perform an action, such as opening a screen, starting a service, or sending a broadcast message.
An Intent can be explicit, where the target component is specified explicitly, or implicit, where the system chooses an appropriate component based on the action and data specified in the Intent.
Example of an explicit Intent to start another Activity:
Intent intent = new Intent(CurrentActivity.this, TargetActivity.class);
startActivity(intent);
Example of an implicit Intent to open a web page:
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://example.com"));
startActivity(intent);
Thus, an Intent serves as a means of communication and navigation within an application and between applications.