When use an Implicit Intent vs an Explicit Intent?
For this Implicit Intent:
Intent searchintent = new Intent()
searchintent.setAction(Intent.ACTION_VIEW) searchintent.setData(Uri.parse("http://www.google.com")) startActivity (searchintent)
How would I set another action and how would I use setData with something other than a Uri parameter?
I am just generally trying to understand both types of intents.
Thanks
Implicit intents is when you want to perform an action but you don't know what application the user currently has to handle that action. For example sending an email, there are many applications for that so the user can choose which application he wants to use.
Explicit intent is used to start an activity within your application, if you have mainactivity, and secondActivity, and you want to start the second activity you call an explicit intent.
StartActivity(new Intent(getBaseContext(), secondActivity.class));
You can pass data between activities by adding extras to the bundle that is being passed with the Intent.
Intent i = new Intent(getBaseContext, secondActivity.class);
i.putExtra("key",value);
startActivity(i);
And to get back the extras in your second activity just call:
getIntent().getStringExtra("key");
Or if you want only to get the "data" uri that was passed you can call
getIntent().getData();
The extra can be for example an int/double/String or a parcable object
http://developer.android.com/reference/android/os/Parcelable.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With