Menus

Wednesday 29 June 2016

Running State Changing Example


Different States of an Android Activity




Methords


 @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");
    }



If you have abstract methods to implement, press Alt+Enter over class name to open a wizard. Otherwise, for overriding a function, just start typing the name of your method (without any access attribute or type), anywhere in your class scope. Then, Android Studio should suggest you overridable methods.


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

Method Overriding in Java

If subclass (child class) has the same method as declared in the parent class, it is known as method overriding in java.
In other words, If subclass provides the specific implementation of the method that has been provided by one of its parent class, it is known as method overriding.

Usage of Java Method Overriding

  • Method overriding is used to provide specific implementation of a method that is already provided by its super class.
  • Method overriding is used for runtime polymorphism

Rules for Java Method Overriding

  1. method must have same name as in the parent class
  2. method must have same parameter as in the parent class.
  3. must be IS-A relationship (inheritance).
-------------------------------------------------------------------------------------------------------------------------



Example of adding different activity in my android application


package com.example.root.myfirstandroidapplication;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.util.Log;


public class MainActivity extends AppCompatActivity {

    private static final String TAG = "MyActivity";

    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Log.i(TAG,"onCreate");
    }

    @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");
    }


    public void onButtonClick(View V){

        EditText e1 = (EditText)findViewById(R.id.editText);
        EditText e2 = (EditText)findViewById(R.id.editText2);
        EditText e3 = (EditText)findViewById(R.id.editText3);

        int num1 = Integer.parseInt(e1.getText().toString());
        int num2 = Integer.parseInt(e2.getText().toString());

        int sum = num1+num2;

       
        e3.setText(Integer.toString(sum));

       
    }

}


Log details of above code run


06-29 11:12:48.872 2996-2996/com.example.root.myfirstandroidapplication I/MyActivity: onCreate
06-29 11:12:48.872 2996-2996/com.example.root.myfirstandroidapplication I/MyActivity: onStart
06-29 11:12:48.872 2996-2996/com.example.root.myfirstandroidapplication I/MyActivity: onResume
06-29 11:28:18.959 2996-2996/com.example.root.myfirstandroidapplication I/MyActivity: onPause
06-29 11:28:19.037 2996-2996/com.example.root.myfirstandroidapplication I/MyActivity: onStop
06-29 11:28:19.037 2996-2996/com.example.root.myfirstandroidapplication I/MyActivity: onDestroy






Friday 24 June 2016

Running a Simple App


Setting up your projects in Android Studio



In this section first explain to setting up your projects on Android Studio.

The first step in the application development process is to create a new project within the Android Studio environment.

First open android studio and goto menu File -> New -> NewProject


New Project 

Once this windows appears, Android studio is ready for a new project to be crated. Fill the all field in new project window.




Target Adroid Studio

This window help to select the form factors your app will run on.

The minimum SDK version determines the lowest level of Android that your app will run on.






Add an Activity to Mobile


The next step is to define the type of initial activity that is to be created for the application.
A range of different activity types is available when developing Android applications. 
simply select the option to create a Blank Activity.






Customize the Activity






Finally, click on Finish to initiate the project creation process.


User Interface Designer tool


This window is used to create user interface and add or edit code. 




Application test to run for click to run button




Running a simple APP


Android Application Add two numbers Calculator adding two numbers in android 

public void onButtonClick(View v){

        EditText e1 = (EditText)findViewById(R.id.editText);
        EditText e2 = (EditText)findViewById(R.id.editText2);
        TextView t1 = (TextView)findViewById(R.id.textView4);


        int num1  = Integer.parseInt(e1.getText().toString());
        int num2  = Integer.parseInt(e2.getText().toString());

        int sum = num1 + num2;

        t1.setText(Integer.toString(sum));

        
    }

}

















Thursday 23 June 2016

What is Android


What is Android

Android is an open source operating system, created by Google specifically for use on mobile devices (cell phones and tablets)

Linux based (2.6 kernel)

Can be programmed in C/C++ but most app development is done in Java (Java access to C Libraries via JNI (Java Native Interface))

Supports Bluetooth, Wi-Fi, and 3G and 4G networking

Android has a large number of applications available for download in Google play store. Around 1 million apps are published and over 50 billion downloads.

 According to survey conducted in April-May 2013 found that Android is the most popular platform for developers .It is used by almost 71% of the mobile developer’s population.

Google Proudly announced that 1 billion activated devices now use the Android OS worldwide.

Android was founded by  Andy Rubin(co-founder of Danger),

Rich Minner(co-founder of wild-fire communications)and

Chris White(headed design and interface development  at WebTV).

Android Application Life Cycle

The Android application life cycle is unique in that the system controls much of the life cycle of the application. All Android applications, or Activities, are run within their own process. All of the running  processes are watched by Android and, depending on how the activity is running (this is, a foreground activity, background activity, and so forth),Android may choose to end the activity to reclaim needed resources.
An activity represents a single screen with a user interface just like window or frame of Java.Android activity is the subclass of ContextThemeWrapper class.
If you have worked with C, C++ or Java programming language then you must have seen that your program starts from main() function. Very similar way, Android system initiates its program with in an Activity starting with a call ononCreate() callback method. There is a sequence of callback methods that start up an activity and a sequence of callback methods that tear down an activity as shown in the below Activity life cycle diagram:





Some of the specific methods and description

onCreate()      This is the first callback and called when the activity is first created.

onStart()         This callback is called when the activity becomes visible to the user.

onResume()     This is called when the user starts interacting with the application.

onPause()        The paused activity does not receive user input and cannot execute any code and                                   called when the current activity is being paused and the previous activity is being                                 resumed.

onStop()          This callback is called when the activity is no longer visible.

onDestroy()     This callback is called before the activity is destroyed by the system.

onRestart()       This callback is called when the activity restarts after stopping it.





























Wednesday 22 June 2016

Develop Android Application

Android software development


Android software development is the process by which new applications are created for the Android operating system. Applications are usually developed in Java programming language using the Android software development kit (SDK), but other development environments are also available.


Integrated development environment (IDE) 

Eclipse using the Android Development Tools (ADT) Plugin.

NetBeans IDE also supports Android development via a plugin.

Android Studio is the official integrated development environment (IDE) for Android platform development.


Java download

http://www.oracle.com/technetwork/java/javase/downloads/index-jsp-138363.html


Installing Android Studio


Android Studio provides the fastest tools for building apps on every type of Android device.
World-class code editing, debugging, performance tooling, a flexible build system, and an instant build/deploy system all allow you to focus on building unique and high quality apps.

https://developer.android.com/studio/index.html