Look @ Android Intent 📱

Ramkumar N
3 min readApr 23, 2017

--

Understanding The Basic’s of Android Intent

What is Android Intent đź‘Ť

An Intent is a Trigger object in android system which can request to starting an activity or starting a service or delivering a broadcast messages to other apps in the android system.

đź“Ž Starting an Activity
An Activity represents a single window in an application.you can start a new activity by passing a Intent object to startActivity() method.The Intent object describes the activity to start and holds any required data to pass other activity and we can also get the passed data from the previous activity in the newly created activity by using the Intent object.

đź“Ž Stating a Service
By Using an Intent object we can start the Android Service. an Android Service is a Component which performs one time operation like Downloading a file in the background without the user interaction by passing Intent to startService() method (we can discuss it further come tutorials).

đź“Ž Delivering Broadcast
A Broadcast is a Message that any application can receive depends on the system events like boot,charging etc.By using Intent object to we can deliver the broadcast by passing Intent to sendBroadcast() or sendOrderdBroadcast() (we can discuss it further come tutorials).

Types Of Intent

đź“Ś Explicit Intent

Explicit Intent is an Intent Which specifies the component by Name (fully qualified class name) to Starting an Activity or Starting a Service in your own application because you know your class name you may want to start either an activity or a service.

Screen_One.javatext = meditText.getText().toString().trim();
Intent explicitIntent = new Intent(getApplicationContext(),Screen_Two.class);
explicitIntent.putExtra("valueToken",text);
startActivity(explicitIntent);
Screen_Two.javatextView = (TextView)findViewById(R.id.text1);
data = getIntent().getStringExtra("valueToken");
textView.setText(data);
Explicit Intent

đź“Ś Implicit Intent

Implicit Intent is an Intent which do not name a specific component but instead declare a general action to perform which allows a component from another application to handle it.for example now you’re using whatsapp if you want to share a text message or an image to others who are not in whatsapp. in this situation android provides an Implicit Intent which the user can select the application by app chooser.so we can share that data via any one of the other apps like hangouts,facebook,mail,message etc

Share Text via Implicit Intent

text2 = meditText2.getText().toString().trim();
Intent implicitIntent = new Intent(Intent.ACTION_SEND);
implicitIntent.setType("text/plain");
implicitIntent.putExtra(Intent.EXTRA_TEXT,text2);
if(implicitIntent.resolveActivity(getPackageManager()) != null) {
startActivity(Intent.createChooser(implicitIntent, "Share To Others"));
}
Implicit Intent — Share Text

Share Image via Implicit Intent

Intent implicitIntentImage = new Intent(Intent.ACTION_SEND);
implicitIntentImage.setType("image/*");
Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.drawable.android);
String path = MediaStore.Images.Media.insertImage(getContentResolver(),bitmap,"Title",null);
Uri uri = Uri.parse(path);
implicitIntentImage.putExtra(Intent.EXTRA_STREAM,uri);
if(implicitIntentImage.resolveActivity(getPackageManager()) != null)
{
startActivity(Intent.createChooser(implicitIntentImage, "Share Image Using"));
}
Implicit Intent — Share Image

Pending Intent

PendingIntent is basically an object that wraps another Intent object. Then it can be passed to a foreign application where you’re granting that app the right to perform the operation (we can discuss it further come tutorials).

Hope you have enjoyed this post,Feel free to comment below for doubts or chat with me in Facebook or drop me e-mail for replies. Share is care.

--

--