Sunday, February 12, 2017

Introduction to Android

What is Android?

Android is an operating system based on the Linux kernel with a user interface based on direct manipulation.
  •  Android is an open source software platform created by Google and the open handset Alliance.
  •  It is primarily used to power mobile phones. 
  •  Android consist of a complete set of software components for mobile devices including:
  •  An operating system
  •  A middle-ware, and
  •  Embedded key mobile application
  •  A large market

What is open handset alliance?

  • “… Open Handset Alliance™, a group of 47 technology  an d mobile companies  have come together to accelerate  innovation in mobile and offer consumers a richer, less  ex pensive, and better mobile experience.   
  • Together we have developed Android™, the first  complete open and free mobile platform complete, open, and free mobile platform.
  • We are committed to commercially deploy handsets and  services using the Android Platform.

The Android Platform

  • Android is a software environment built for mobile  devices. 
  • It is not a hardware platform.
  • Android includes:
  • Linux-kernel based OS 
  • A rich UI 
  • Telephone functionality,  
  • End‐user applications, 
  • Application frameworks,

Android Components (Stack) 

  • The Android stack includes a large array of features for mobile applications. 
  • It would be easy to confuse Android with a  general purpose computing environment. 
  • All of the major components of a computing platform are included. 

Applications Life Cycle

  • An unusual and fundamental feature of android is that an application process’s life time is not directly controlled by the application itself. Instead, it is determined by the system through a combination of 
  1. the parts of the application that the system knows are running, 
  2. how important these things are to the user, and 
  3. How much overall memory is available in the system. 

Activity Stack 

  • Activities in the system are managed as an activity stack. 
  •  When a new activity is started, it is placed on the top of the  stack and becomes the running activity ‐‐the previous  activity always remains below it in the stack, and will not  come to the foreground a gain until the new activity exits.
  •  If the user presses the Back Button the next activity on the  stack moves up and becomes active. 

Creating an Android Project

Creating an Android Project

 This lesson shows you how to create a new Android project with Android Studio and describes some of the files in the project. As Android devices become increasingly more common, demand for new apps will only increase. Android Studio is an easy to use (and free) development environment to learn on.

  • Open Android Studio from search box.
  • Create a new project.
  • If you are using android studio first time then there will be the first tab for creating a new  project. Click on that tab.
  • If you have a project opened then Click File > New Project.
  • In the new project screen enter the following values
  • Application Name: "Write Application Name"
  • Company Domain: "Enter Unique Domain name" 
  • Project Location: Select Project Location Where you want to save project.
  • Android Studio fills in the package name and project location for you, but you can edit these if you'd like.
  • In the Target Android Devices screen
  • Select Phone and Tablet.
  • Select minimum required SDK version. Minimum required SDK version is the earliest version of Android that your app support. 
  • Click Next
  • Select Empty or Basic Activity for the very first time.
  • Click Next
  • In the Customize the Activity screen, keep the default values and click Finish
Complete YouTube Video Tutorial Here


 

Wednesday, February 1, 2017


Linear Layout

Linear Layout organizes elements along a single line. You specify whether that line is vertical or horizontal using android:orientation. Here is a sample Layout XML using Linear Layout. Change Orientation horizontal if you want to adjust widgets horizontally.

<LinearLayout
 xmlns:android="http://schemas.android.com/apk/res/android"
 android:orientation="vertical"
 android:layout_width="match_parent"
 android:layout_height="match_parent">

 <Button
 android:id="@+id/backbutton"
 android:text="Back"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content" />

<TextView
 android:text="First Name"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content" />

<EditText
 android:width="100px"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

<TextView
android:text="Last Name"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

 <EditText
android:width="100px"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

</LinearLayout>

Relative Layout

 RelativeLayout lays out elements based on their relationships with one another, and with the parent container. This is arguably the most complicated layout, and we need several properties to actually get the layout we want.

<RelativeLayout
 xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:paddingLeft="16dp"
 android:paddingRight="16dp" >

 <EditText
android:id="@+id/name"
 android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/reminder" />
 
<Spinner
 android:id="@+id/dates"
 android:layout_width="0dp"
 android:layout_height="wrap_content"
 android:layout_below="@id/name"
 android:layout_alignParentLeft="true"
android:layout_toLeftOf="@+id/times" />

<Spinner
android:id="@id/times"
android:layout_width="96dp"
android:layout_height="wrap_content"
android:layout_below="@id/name"
android:layout_alignParentRight="true" />

<Button
android:layout_width="96dp"
android:layout_height="wrap_content"
android:layout_below="@id/times"
android:layout_alignParentRight="true"
android:text="@string/done" />

</RelativeLayout>

Monday, January 23, 2017


onCreate():

  • Called when the activity is first created. 
  • This is where you should do all of your normal static set up create views, bind data to lists, an d so on.
  • Always followed by onStart()

onRestart():

  • Called after the activity has been stopped, just prior to it bein g started again. 
  • Always followed by onStart()

onStart():

  • Called just before the activity becomes visible to the user.
  • Followed by onResume() if the activity comes to the foreground, or onStop() if it becomes hidden.

onResume():

  •  Called just before the activity starts interacting with the user. 
  •  At this point the activity is at the top of the activity stack, with user input going to it. 
  • Always followed by onPause().

Activity Running:

  • It is active or running when it is in the foreground of the screen (at the top of the activity stack for the current task). 
  • This is the activity that is the focus for the user's actions.

onPause():

  •  Called when the system is about to start resuming another activity. 
  •  This method is typically used to commit unsaved changes to persistent data, stop animations and other things that may be consuming CPU, and so on. 
  • It should do whatever it does very quickly, because the next activity will not be resumed until it returns. 
  • Followed either by onResume() if the activity returns back t o the front, or by onStop() if it becomes invisible to the user. The activity in this state is killable by the system.

onStop():

  • Called when the activity is no longer visible to the user. 
  • This may happen because it is being destroyed, or because another activity (either an existing one or a new one) has been resumed and is covering it.
  •  Followed either by onRestart() if the activity is coming back to interact with the user, or by onDestroy() if this activity is going away. 
  • The activity in this state is killable by the system.

onDestroy():

  • Called when the activity is no longer visible to the user. 
  •  This may happen because it is being destroyed, or because another activity (either an existing one or a new one) has been resumed and is covering it. 
  • Followed either by onRestart() if the activity is co ming back to interact with the user, or by onDest roy() if this activity is going away. 
  • The activity in this state is killable by the system.

Life Cycle Functions:

 @Override
    protected void onStart() {
        super.onStart();
        Log.i(TAG, "onStart");
    }


    @Override
    protected void onResume() {
        super.onResume();
        Log.i(TAG, "onResume");
    }


    @Override
    protected void onPause() {
        super.onPause();
        Log.i(TAG, "onPause");
    }


    @Override
    protected void onStop() {
        super.onStop();
        Log.i(TAG, "onStop");
    }


    @Override
    protected void onRestart() {
        super.onRestart();
        Log.i(TAG, "onRestart");
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
        Log.i(TAG, "onDestroy");
    }


    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        Log.i(TAG, "onSaveInstanceState");
    }


    @Override
    protected void onRestoreInstanceState(Bundle savedInstanceState) {
        super.onRestoreInstanceState(savedInstanceState);
        Log.i(TAG, "onRestoreInstanceState");
    }