Unit-3 Android UI Design Essentials [IMP QUESTION IN MID-2]

Q-1) Intent and its types 

-Android uses Intent for communicating between the components of an application and also from one

application to another application. 

                                OBJECT

                                    🠑

                                INTENT

                                     🠑

                                LABELEDINTENT

-For example: Intent facilitate you to redirect your activity to another activity on occurrence of any event. By calling, startActivity() you can perform this task.

- Intent intent = new Intent(getApplicationContext(), SecondActivity.class); 

    startActivity(intent);

[2] Types of Intents 

Intent is of two types: Explicit Intent and Implicit Intent

I) Explicit Intent: 

     Explicit Intents are used to connect the application internally. 

     In Explicit we use the name of component which will be affected by Intent. For Example: If we             know class name then we can navigate the app from One Activity to another activity using Intent.            In the similar way we can start a service to download a file in background process.

Intent intent = new Intent(getApplicationContext(), SecondActivity.class); 

startActivity(intent);  


II) Implicit Intent:

     In Implicit Intents we do need to specify the name of the component. We just specify the Action             which has to be performed and further this action is handled by the component of another                     application. 

     The basic example of implicit Intent is to open any web page

   Intent intentObj = new Intent(Intent.ACTION_VIEW);             intentObj.setData(Uri.parse("https://developer.android.com"));
 startActivity(intentObj);

- Unlike Explicit Intent you do not use any class name to pass through Intent(). In this example we has just specified an action. Now when we will run this code then Android will automatically start your web browser and it will open AbhiAndroid home page.

-----------------------------------------------------------------------------------------------------------------------------

Q-2) GUI architecture 

 The Android environment adds yet another Graphical User Interface (GUI) toolkit to the Java AWT, Swing, and J2ME. If you’ve worked with any of these, the Android framework will look familiar.

 The Android UI framework is, like the other UI frameworks, organized around the common Model-View-Controller . It provides structure and tools for building a Controller that handles user input and a View that renders graphical information to the screen.


1-The View :

 The View is the application’s feedback to the user. It is the portion of the application responsible for rendering the display, user feedback, etc. The graphical portion of the Android UI framework’s View. 

 As an example, the display in a hypothetical MP3 player might contain a component that shows the album cover for the currently playing tune. Another component might display the name of the currently playing song, while a third contains subcomponents such as the Play, Pause, and Stop buttons.  

2-The Controller :

 The Controller is the portion of an application that responds to external actions: a keystroke, a screen tap, an incoming call, etc. It is implemented as an event queue. Each external action is represented as a unique event in the queue. The framework removes each event from the queue in order and dispatches it. 

 For example, when a user presses a key on his phone, the Android system generates a KeyEvent and adds it to an event queue.  

3-The Model :

 The Model is the guts of your application: what it actually does. It might be, for instance, the database of tunes on your device and the code for playing them. It might be your list of contacts and the code that places phone calls or sends IMs to them. 

 While a particular application’s View and Controller will necessarily reflect the Model they manipulate, a single Model might be used by several different applications. 

 User Interface design, human–computer interaction, and usability are huge topics. it’s important that you get them right when creating your User Interfaces

    I) Views: Views are the basic User Interface class for visual interface elements (commonly known as controls or widgets). All User Interface controls, and the layout classes, are derived from Views.

    II) View Groups: View Groups are extensions of the View class that can contain multiple child Views. By extending the ViewGroup class, you can create compound controls that are made up of interconnected child Views. The ViewGroup class is also extended to provide the layout managers, that help you compose User Interfaces.  

MAKE A  DIAGRAM

III) Activities: Activities are the Android equivalent of a Form. To display a User Interface, you assign a View or layout to an Activity.

-----------------------------------------------------------------------------------------------------------------------------

Q-3)Layouts

 Layouts are Android’s solution to the variety of screens that come on Android devices: they can have different pixel densities, different dimensions, and different aspect ratios. Typical Android devices allow changing the screen orientation while applications are running, so the layout infrastructure needs to be able to respond on the fly. 

 Layouts are intended to give developers a way to express the physical relationship of Views as they are drawn on the screen. 

Layout is a two-pass process: 

 Measure pass 

 Traversing the tree from the root, each View in the layout records its dimensional request—in other words, how much vertical height and horizontal width it needs to display itself in the final display. 

 Layout pass 

 Again traversing the tree from the root, each parent View uses the available layout information to position its children as requested. If the requests can’t be followed explicitly, Android does its best to make everything fit on the screen. If there are no requests given, it uses a default set of layout parameters. 

TYPES OF LAYOUT :

 LinearLayout Organizes its children either horizontally or vertically. 

 TableLayout Organizes its children in tabular form. 

 RelativeLayout Organizes its children relative to one another or to the parent. 

 Grid Layout A layout that places its children in a rectangular grid. 

 FrameLayout Allows you to dynamically change the control(s) in the layout.  

--------------------------------------------------------------------------------

1- LinearLayout 

 LinearLayout is used when we need to arrange the widgets/views in a horizontal or vertical manner. The direction of arrangement can be set to horizontal or vertical, by default it is being horizontal.  

2- Relative Layout 

 Using the Relative Layout, you can define the positions of each of the child Views relative to each other and the screen boundaries.  The Relative Layout is very flexible layout used in android for custom layout designing.

Even though Android has drag and drop system to put one component in related to other inside relative layout. But actually, in the background lots of XML properties are working which does this task.

3-Table Layout 

 If the Layout's widgets/views need to be arranged in the form of rows and columns, we use this layout object. This is similar to html tables. The cells can span columns. The TableLayout do not display its border.  

 In Android, Table Layout is used to arrange the group of views into rows and columns. Table Layout containers do not display a border line for their columns, rows or cells.

4-Grid Layout 

 Grid Layout is a layout that divides its view space into rows, columns, and cells. Grid Layout places views in it automatically, but it is also possible to define the column and row index to place a view into Grid Layout. With the span property of cells, it is possible to make a view span multiple rows or columns.

5-Frame Layout 

 The simplest of the Layout Managers, the Frame Layout simply pins each child view to the top left corner. Adding multiple children stacks each new child on top of the previous, with each new View obscuring the last.

Absolute Layout :

An Absolute Layout lets you specify exact locations (x/y coordinates) of its children. Absolute layouts are less flexible and harder to maintain than other types of layouts without absolute positioning.

AbsoluteLayout Attributes 

Following are the important attributes specific to AbsoluteLayout − 

Sr.No     Attribute & Description 

1             android:id  - This is the ID which uniquely identifies the layout. 

2             android:layout_x  - This specifies the x-coordinate of the view. 

3             android:layout_y  - This specifies the y-coordinate of the view.  

Public Constructors 

AbsoluteLayout(Context context) 

AbsoluteLayout(Context context, AttributeSet attrs) 

AbsoluteLayout(Context context, AttributeSet attrs, int defStyleAttr) 

AbsoluteLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) 

-----------------------------------------------------------------------------------------------------------------------------

Q-4) Diff Relative layout and linear layout 

Difference between Liner Layout and Relative Layout. 

RELATIVE LAYOUT: 

● Every element of relative layout arranges itself to the other element or a parent element. 

● It is helpful while adding views one next to other etc 

● In a relative layout you can give each child a Layout Property that specifies exactly where it should go in relative to the parent or relative to other children. 

● Views can be layered on top of each other. 

LINEAR LAYOUT: 

● In a linear layout, like the name suggests, all the elements are displayed in a linear fashion either vertically or horizontally. 

● Either Horizontally or Vertically this behavior is set in android:orientation which is an property of the node Linear Layout. 

● Linear layouts put every child, one after the other, in a line, either horizontally or vertically. android: orientation= " horizontal" or android: orientation= " vertical" 

-----------------------------------------------------------------------------------

Q-5) Adapter

Adapter In Android,

 Adapter is a bridge between UI component and data source that helps us to fill data in UI component. It holds the data and send the data to an Adapter view then view can take the data from the adapter view and shows the data on different views like as ListView, GridView, Spinner etc. For more customization in Views, we use the base adapter or custom adapters. To fill data in a list or a grid we need to implement Adapter. Adapters acts like a bridge between UI component and data source. Here data source is the source from where we get the data and UI components are list or grid items in which we want to display that data. 

Below is a conceptual diagram of Adapter:



Adapters In Android: 

There are the some commonly used Adapter in Android used to fill the data in the UI components. BaseAdapter – It is parent adapter for all other adapters 

ArrayAdapter – It is used whenever we have a list of single items which is backed by an array 

Custom ArrayAdapter – It is used whenever we need to display a custom list 

SimpleAdapter – I t is an easy adapter to map static data to views defined in your XML file 

Custom SimpleAdapter – It is used whenever we need to display a customized list and needed to access the child items of the list or grid 

Now we describe each Adapters one by one in detail:

1. BaseAdapter In Android: BaseAdapter is a common base class of a general implementation of an Adapter that can bused in ListView, GridView, Spinner etc. Whenever we need a customized list in a ListView or customized grids in a GridView we create our own adapter and extend base adapter in that. Base Adapter can be extended to create a custom Adapter for displaying a custom list item. ArrayAdapter is also an implementation of BaseAdapter.  

2. ArrayAdapter In Android: Whenever we have a list of single items which is backed by an Array, we can use ArrayAdapter. For instance, list of phone contacts, countries or names.  

3. Custom ArrayAdapter In Android: ArrayAdapter is also an implementation of BaseAdapter, so if we want more customization then we can create a custom adapter and extend ArrayAdapter in that. Since array adapter is an implementation of BaseAdapter, so we can override all the function’s of BaseAdapter in our custom adapter

4. SimpleAdapter In Android:In Android SimpleAdapter is an easy Adapter to map static data to views defined in an XML file(layout). In Android we can specify the data backing to a list as an ArrayList of Maps(i.e. hashmap or other). Each entry in a ArrayList is corresponding to one row of a list. The Map contains the data for each row. Here we also specify an XML file(custom list items file) that defines the views which is used to display the row, and a mapping from keys in the Map to specific views

5. Custom SimpleAdapter In Android: Whenever we have to create a custom list we need to implement custom adapter. As we discuss earlier ArrayAdapter is used when we have a list of single item’s backed by an Array. So if we need customization in a ListView or a GridView we need to implement simple Adapter but when we need more customization in list or grid items where we have many view’s in a list item and then we have to perform any event like click or any other event to a particular view then we need to implement a custom adapter who fulfills our requirement’s and quite easy to be implemented.

-----------------------------------------------------------------------------------------------------------------------------

Q-6) Fragment lifecycle

WHAT IS FRAGMENT ?

(1) The fragment is only part of an activity, it basically contributes its UI to that activity. 

(2) Fragment is dependent on activity. It can’t exist independently. 

(3) Fragment is not required to mention in the manifest file 

(4) After using multiple fragments in a single activity, we can create a multi-screen UI. 

(5) Fragment cannot be used without an Activity. 

(6) While Using fragments in the project, the project structure will be good and we can handle it easily. 

(7) Lifecycle methods in fragments are hosted by hosting the activity. 

(8) The fragment is the lite weight. 

Fragment Life Cycle :

Android fragments have their own life cycle very similar to an android activity. This section briefs different stages of its life cycle.  












Here is the list of methods which you can to override in your fragment class − 

 onAttach()The fragment instance is associated with an activity instance.The fragment and the activity is not fully initialized. Typically you get in this method a reference to the activity which uses the fragment for further initialization work. 

 onCreate() The system calls this method when creating the fragment. You should initialize essential components of the fragment that you want to retain when the fragment is paused or stopped, then resumed. 

 onCreateView() The system calls this callback when it's time for the fragment to draw its user interface for the first time. To draw a UI for your fragment, you must return a View component from this method that is the root of your fragment's layout. You can return null if the fragment does not provide a UI. 

 onActivityCreated()The onActivityCreated() is called after the onCreateView() method when the host activity is created. Activity and fragment instance have been created as well as the view hierarchy of the activity. At this point, view can be accessed with the findViewById() method. example. In this method you can instantiate objects which require a Context object 

 onStart()The onStart() method is called once the fragment gets visible. 

 onResume()Fragment becomes active. 

 onPause() The system calls this method as the first indication that the user is leaving the fragment. This is usually where you should commit any changes that should be persisted beyond the current user session. 

 onStop()Fragment going to be stopped by calling onStop() 

 onDestroyView()Fragment view will destroy after call this method 

 onDestroy()onDestroy() called to do final clean up of the fragment's state but Not guaranteed to be called by the Android platform. 

-----------------------------------------------------------------------------------------------------------------------------

Q-7) Diff activity and fragment







Comments

Popular posts from this blog

Build a Complete Responsive Personal Portfolio using PHP, HTML,CSS,JAVASCRIPT || PART #3 Coding