Junior — Middle
Can you list the main types of Intent used in Android app development?
sobes.tech AI
Answer from AI
In Android, there are several main types of Intent used for different purposes:
-
Explicit Intent: used to launch a specific component of an application (Activity, Service) when the exact class is known.
-
Implicit Intent: used to launch components that can handle a certain action or data, without specifying a particular class. The system chooses the appropriate component.
-
Broadcast Intent: used to send broadcast messages that can be received by multiple applications or components.
-
Intent for launching an Activity: for transitioning between screens.
-
Intent for launching a Service: for starting background tasks.
Example of an explicit Intent to launch an Activity:
val intent = Intent(this, DetailActivity::class.java)
startActivity(intent)
Example of an implicit Intent to open a web page:
val intent = Intent(Intent.ACTION_VIEW, Uri.parse("https://example.com"))
startActivity(intent)