Sobes.tech
Junior — Middle

How can you initiate the launch of another component via Intent in Android?

sobes.tech AI

Answer from AI

In Android, to launch another component (such as an Activity or Service) via Intent, you can create an Intent object and call the startActivity() or startService() method.

Example of launching another Activity:

Intent intent = new Intent(CurrentActivity.this, TargetActivity.class);
startActivity(intent);

If you need to pass data, you can add it to the Intent:

intent.putExtra("key", "value");
startActivity(intent);

To launch a component by action or category, you can use explicit or implicit Intents. For example, an implicit Intent to open a web page:

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://example.com"));
startActivity(intent);

Thus, Intent serves as a connection between application components or even between different applications.