Implicit and Explicit Intent Example

Android OS Activity have two types intent.

1) Implicit Intent::

Implicit Intents have not specified a component; instead, they must include enough information for the system to determine which of the available components is best to run for that intent.

Button openBrowser= (Button)findViewById(R.id.bOpenBrowser);

bOpenBrowser.setOnClickListener(new OnClickListener() {

public void onClick(View v) {

Intent webIntent = new Intent(Intent.ACTION_VIEW, Uri.pars(“http://www.google.com”));
startActivity(webIntent);

}

});

2) Explicit Intent::

Explicit Intents have specified a component (via setComponent(ComponentName) or setClass(Context, Class)), which provides the exact class to be run. Often these will not include any other information, simply being a way for an application to launch various internal activities it has as the user interacts with the application.

Button openGame= (Button)findViewById(R.id.bOpenGame);

openGame.setOnClickListener(new OnClickListener() {

public void onClick(View v) {

Intent launchExplicitIntent = new Intent(this, Game.class);
startActivity(launchExplicitIntent);

}

});

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: