Some rundowns on Intent

1. What is an intent?

Intent comes from the word “Intention”. In Android, intents are used to communicate asynchronous messages between Android components, either from same application or from other applications.

Example:

  • An activity on interaction with user can request for another activity.
  • An activity of one app can request for taking pictures using inbuilt camera app of your phone.

The Intent class (android.content.intent) in Android is used to display and show our intentions.

We create an object of Intent, passing arguments what we want to do (moving from one activity to another) and pass it to ActivityManager. It will decide when to  start the activity.

Intents can be used to start activities, services, broadcast receivers.

2. How to request for another activity from one activity in code?

Intent has a lot of overloaded constructors.
Intent i = new Intent(source, destination)

source ⇒current context (MyActivity.this)
destination ⇒ requested class (NewActivity.class)

Intent i = new Intent(MyActivity.this, NewActivity.class);
startActivity(i);

Activities which are started by other Android activities are called sub-activities.

3. How to pass messages via intent in code?

An intent can pass data via Bundle.

Example: You want to send the username from one Android activity to next activity.These data can be passed via Bundle by intent.

The reuse of other application components in Android is known as task.

Example: From component of your application, you may need to access Phone Book app of you phone. From your application, you open the PhoneBook app, select one contact, and then return the selected data to your application again.

4. What are the types of intent?

There are two types of intents. These are:-

  • Implicit Intent

Calling using Intents:


Uri num = Uri.parse(“tel:”+phNum)
Intent i = new Intent(Intent.ACTION_CALL, num)
startActivity(i)
Sending sms Intents:


Uri num = Uri.parse(“sms:”+phNum)
Intent i = new Intent(Intent.ACTION_SENDTO, num)
i.putExtra(“sms_body”, “…..”)
startActivity(i)

Accessing Web Links


Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(“fordoxblog.wordpress.com”));
startActivity(i);

  • Explicit Intent

Introducing Views

Views are the rectangular shaped, basic building block of a layout or user interface that assures some content on the screen. Views – as the name suggests – is used to view any content on the screen. Without it, it is not possible to display anything on the screen. Thus it is the most essential element of any UI screen.

Views can me of various geometric shapes and sizes. These can be combined to form advanced views. All of these views and combinations form the layout of a screen. Here, I give an example of a view, complete with markings for easier understanding.

WhatsApp Image 2016-08-17 at 8.33.00 PM (1)

WordBin Login Page

This is a screenshot of one of our published apps, WordBin. Here I have marked the views in black. These views when grouped together, formed the Login page (layout). Any such combination forms different layouts.

Here, it is clearly visible that the bounds of the views can both me transparent (view marked “1”) due to it’s background, and can also be clearly distinguished (view marked “2”). Using the various properties of the views and using its features we can design any view as per our requirement.

Talking from a more programmatic point of view, View is an Android Base class from which all other types of views inherit.

Most Commonly Used Android Views:

  • TextView
  • EditText
  • Button
  • ImageView
  • ImageButton
  • CheckBox
  • RadioButton
  • RadioGroup
  • ListView
  • Spinner
  • AutoCompleteTextView

Since in Java, the norm is to follow Camel Case, the above classes follow such specifications. The above are just a few library classes of the vast Android library. Developers can define custom views and layouts as well on XML files. These custom views must be bound by some Android rules, but mostly they are flexible.

XML (Extensible Markup Language) files store the design of each user interface and  Java is required to implement it’s interactivity with other Java files. Android Studio is the most commonly used IDE to design the entire application.

The intention of this post was to give a basic idea of the View element of Android. Professional developers don’t memorize everything. Looking up information and implementing them properly is a key part of the job. But to implement properly, one should have their concepts clear. There are online sources which I found very useful while developing applications and which I used to refer to for implementing codes. But most of these concepts were not clearly stated in those sources. I learnt these over time after developing many applications. Hope this helps you.

Subscribe and keep checking for more posts soon.

Thank You.