Recent Posts

Site Creator

By

By

By

Day 2 : An Insight to Android Components

Posted on

Dear Friends

Lets start with the solution to our last problem where we need to design a very simple login Screen.

 

MVC : Model View Controller  A design pattern that lays foundation for developing program in Android.

Model : .java classes that hold the data.

View :  .xml classes that holds view that is shown on the screen

Controller : .java classes that glue Model and View.

So our main activity would be like …

 

public class MainActivity extends AppCompatActivity {

 

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

initUI();

 

}

 

/**

Initialize UI here

*/

public void initUI() {

}

}

 

Lets understand what we did. Rather than inflating our UI Elements directly in onCreate method we just delegate this method initUI that we call from onCreate().

So what’s the benefit : Code becomes more readable.  Its not mandatory to do this. But as per my experience code becomes more readable and also if there’s some problem during inflating UI Elements so android studio will report error in logs in initUI method so it will be easier to debug program.

So our view.xml would be like below

 

Run and enjoy apk on device.

 

Now lets discuss about today topic :

 

Android Components

Android Application has following components

  1. Activity
  2. Broadcast Receivers
  3. Services
  4. Content Providers

So in more details

Activity

Activity is an android component which is responsible for showing UI on the screen, interacting with User. Or in other words we can say activity is a component with a face. A face which user can interact with , a face which user can see.

Broadcast Receivers 

Suppose government has made a change to the financial policies so it notifies public through circulars in newspapers, Television, Internet etc. Same analogy applies on Broadcast Receiver. So our app gets notified by the system by means of Broadcast Receivers whenever anything interesting action happens in system. By interesting I mean those actions which are interesting for our application , might be other applications are not interested in those actions. Unlike activity this component has no face.

Services

In our daily life we use many services to get the task done more efficiently . For eg we use a newspaper service to get our newspaper. We don’t directly got newspaper publishing press and procure our newspaper since that won’t be cost effective. Rather we contract with some service dealer and use his service because we know that newspaper dealer is far more efficient than us when it comes in procuring newspaper in cost effective way.  Similarly services are designed for doing a specific task more efficiently.  We will drill down to study more about services and their features later in other tutorial.

Content Providers

Component of Android , that deals with accessing , manipulating, deleting and sharing Data across same or different process(s) in Android.

 

There are different other important supporting actors

Intent 

Asynctask

 

Homework :

Create an android application having more than one activity that interlinks two activities through button press.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 







Disclaimer: The aforesaid writeup by Relsell Global writer is for the general understanding of the readers. It does not render any professional advice or opinion.

SHARE THIS PAGE!

Leave a Reply

Your email address will not be published. Required fields are marked *