Junior — Middle
What is the difference between implicit and explicit intents in Android, and how to use them?
sobes.tech AI
Answer from AI
In Android, intents come in two types: explicit and implicit.
-
Explicit Intent — explicitly specifies a particular component (e.g., Activity or Service) to be started. Used when you know exactly which component you want to invoke.
val intent = Intent(this, DetailActivity::class.java) startActivity(intent) -
Implicit Intent — does not specify a particular component, but describes an action to perform. The system chooses the appropriate application or component capable of handling this intent.
val intent = Intent(Intent.ACTION_VIEW) intent.data = Uri.parse("https://example.com") startActivity(intent)
Usage:
- Use explicit intent for navigation within your app.
- Use implicit intent for interacting with other apps or system functions (e.g., open a browser, make a call, send an email).