How to setup or configure environment variable for android sdk tools inwindows

In this post we will see about how to setup or configure android tools and platoform tools with the system environment variable in windows .

Setting up environment variable ,make it easier to launch the Android tools and work with android commands

Make Sure you have already installed android sdk before , if not the visit   How to installing android sdk

After successfully installing android sdk and configuring it with eclipse , now it's time to setup environment variable for android



lets go step by step

Step 1
                 Click on windows -> computer ->Properties



Step 2   
          In Properties window  click on "Advanced system settings"



Step 3  
 now system properties dialog comes up there click on "Environment variable"



Step 4   
Environment variable dialog comes up there under system variables click on "New" button , on click of "new" a dialog box 
comes up there enter the "Variable name" and "Variable value"
            
                 Variable name can be anything , in my case i have given "ANDROID_HOME"
 
Variable value should be android sdk installed directory  path upto "android-sdk"
                 in my case the value is "C:Program Files (x86)Androidandroid-sdk"
 
Enter the variable name and it's value in the popup dialog and then click ok



Step 5  
now inside system variables select the variable with name "Path" and click on "Edit" button , on click of "Edit" a dialog box comes there edit the variable value

value for SDK tools = %ANDROID_HOME%tools;
value for android platform tools= %ANDROID_HOME%platform-tools;

so add the following value
;%ANDROID_HOME%tools;%ANDROID_HOME%platform-tools;  to the end of path variable values and click ok

 thats it your done :)



Step 6  
To verify the environment variable has set or not , just  open command prompt and enter the following command  "adb version"






Read More »

How to Reboot Android Device In Safe Mode


On your Windows PC, you can boot into safe mode to load Windows without any third-party software. You can do the same thing on Android with Android’s safe mode. In safe mode, Android won’t load any third-party applications. Rebooting in Safe Mode allows you to troubleshoot your device – if you’re experiencing crashes, freezes, or battery life issues.


To Demonstrate this i have used Android Powered HTC Desire X Device.

Step 1:

Press and hold device power button ,you will see a dialog box from the dialog box long press "Power off" option 
Step 2:

After Long press of "Power off " option you will get another dialog prompt to restart in safe mode click on "Restart" button to restart in safe mode.

After Rebooting In Safe Mode you can see the following below screen with a water mark (Safe mode) at the bottom left .

To Exit From Safe Mode Restart your device in normal mode ( Press and hold device power button and then click on restart button ) .

Read More »

Android StartAcitivity for result Example

Using startActivity we can launch new Activity and pass the data to the newly launched activity and reverse of it that is getting data from launched activity we use startActivityForResult.

When using startActivity, your application won’t receive any notification when the newly launched .
If you use the startActivityForResult() method instead of startActivity  you can receive data from the newly launched subactivity .

Read More »

Android FrameLayout Example

The Frame Layout is designed to display single item at a time , you can add multiple views inside in it,In framelayout the childviews are arranged in the form of stack ,with the most recently added view will be at the top

Lets see an example of framelayout that cantains two textview with different background color

Project Detail
Project Name FrameLayoutDemo
Package com.pavan.framelayoutdemo
Minimum SDK API 8
Target SDK API 17
Theme Holo Light with Dark Action Bar

1. XML Layout


create a xml with framelayout view containing two textview in it with different background color .

file :-frame_layout.xml 
<FrameLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/mainlayout"
 android:layout_height="fill_parent"
 android:layout_width="fill_parent"
 android:orientation="vertical" />

<!-- Green Background -->
        <Textview
               android:background="#00FF00"
               android:gravity="bottom"
               android:id="@+id/textView1"
               android:layout_height="200dp"
               android:layout_width="200dp"
               android:text="TextView One"
               android:textsize="15dp" />

<!-- BLUE Background -->
       <Textview
         android:background="#0000FF"
         android:gravity="bottom"
         android:id="@+id/textView2"
         android:layout_height="100dp"
         android:layout_width="100dp"
         android:text="TextView Two"
         android:textsize="15dp" />

</Framelayout>


Inside the framelayout firstly we added textview with green background and next we added another textview with blue background so the most recently added textview that the blue background one will be displayed at top.


2. Activity


Create a class FrameLayout and extend it to activity class and override the onCreate() method of activity class and set the content of the actvity with the above defined xml file by calling setContentView() method and passing xml file name as a parameter to it
                          setContentView(frame_layout);

file :- FrameLayout.java
package com.pavan.framelayoutdemo;

import android.app.Activity;
import android.os.Bundle;

public class FrameLayout extends Activity {

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.frame_layout);
 }

}

3. RUN


Android FrameLayout



Read More »

Android RadioButton in RadioGroup Example

In this tutorial we will see how to create radio button in android , Radio buttons allow user to select only one option at a time from a given set .
 

In android the RadioButtons usually are grouped under RadioGroup , In a group if you select one RadioButton then others are deselected .

In this tutorial , we will see an example of three Radiobutton  which are grouped under RadioGroup.

android radio buttonandroid radio button



Lets see an example of radio group 

Project Detail
Project Name RadiogroupDemo
Package com.pavan.radiogroupdemo
Minimum SDK API 8
Target SDK API 17
Theme Holo Light with Dark Action Bar

1. XML Layout


file:- activity_main.xml
< LinearLayout
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     android:orientation="vertical"
     android:padding="20px" >

        < RadioGroup
            android:id="@+id/radiogroup_OS"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

                 < RadioButton
                      android:id="@+id/radio_android"
                      android:text="Android" />

                 < RadioButton
                      android:id="@+id/radio_ios"
                      android:text="IOS" />

                 < RadioButton
                      android:id="@+id/radio_windows"
                      android:text="Windows" />
 
     < /RadioGroup>
 
< /LinearLayout>

2. Activity


file : MainActivity.java
package com.pavan.radiogroupdemo;
import com.pavan.androidradiogroupdemo.R;
import android.app.Activity;
import android.os.Bundle;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.Toast;

public class MainActivity extends Activity implements OnCheckedChangeListener {

 RadioGroup radiogroup;
 RadioButton radiobutton;

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  // get the id's of views
  radiogroup = (RadioGroup) findViewById(R.id.radiogroup_OS);

  // set the listeners for the views
  radiogroup.setOnCheckedChangeListener(this);

 }

 @Override
 public void onCheckedChanged(RadioGroup group, int checkedId) {
  // TODO Auto-generated method stub
  radiobutton = (RadioButton) findViewById(checkedId);
  Toast.makeText(this, "You selected: " + radiobutton.getText(),
    Toast.LENGTH_SHORT).show();
 }
}
   
Read More »

Android RelativeLayout With Example

Relative layout is a viewgroup that extends android.view.viewgroup , the relative layout lays it's child views or elements with respect to it siblings or to its parent .

Advantage of Relative Layout Over Other Layouts

  1.  Relative Layout helps in achieve desired user interface efficiently.
  2.  Avoid use of nested linear layout and make use of relative layout because nesting of layout increases the length of xml source file as a result makes it hard to read and also effects the performance of the application . 
Lets See an Example Relative Layout

Project Detail
Project Name Relative_layout
Package com.pavan.relative_layout
Minimum SDK API 8
Target SDK API 17
Theme Holo Light with Dark Action Bar

1. XML Layout


file :- relative_layout.xml
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <Button
        android:id="@+id/button1"
        style="?android:attr/buttonStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:text="Button 1" />

    <Button
        android:id="@+id/button2"
        style="?android:attr/buttonStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="37dp"
        android:layout_toRightOf="@+id/button1"
        android:text="Button 2" />

    <Button
        android:id="@+id/button3"
        style="?android:attr/buttonStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_marginBottom="150dp"
        android:text="Button 3" />

    <Button
        android:id="@+id/button5"
        style="?android:attr/buttonStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/button2"
        android:layout_below="@+id/button2"
        android:layout_marginTop="70dp"
        android:text="Button 5" />

    <Button
        android:id="@+id/button6"
        style="?android:attr/buttonStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/button3"
        android:layout_alignParentRight="true"
        android:layout_marginBottom="22dp"
        android:text="Button 6" />

</RelativeLayout>

2. Activity


Create a Relative_layout.class and extend it to activity class and override the onCreate() method of activity class and set the content of the actvity with the above defined xml file by calling setContentView() method and pass the above defined layout xml file name as a parameter to it

                                    setContentView(relative_layout);

file :- Relative_layout.java
package com.example.com.pavan.relative_layout;
import android.os.Bundle;
import android.app.Activity;

public class Relative_layout extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.relative_layout);
    }
}

3. RUN




In the above Example of Relative Layout

 Button 2 is Right of Button 1
 Button 5 is below Button 2
 Button 3 is above Button 6





Read More »

Android wrap_content and fill_parent example

In android every Tag in Xml file contains two important attributes
  1.  android:layout_width
  2.  android:layout_height
This Attribute take value either wrap_content or fill_parent and this value specify the height or width of the requested View.

Lets see the Definition

1.     wrap_content: – The component just want to display big enough to enclose its content only.

2.     fill_parent :– The component want to display as big as its parent, and fill in the remaining spaces. (renamed match_parent in API Level 8) .


Lets See an Examples for better understanding

Create an android xml file that contains Button inside linear layout and change the attribute values of android:layout_width and android:layout_height for button view and see the changes.


1. View With
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"


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

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Pavan"
        android:textSize="30dp" />

</LinearLayout>




2. View With
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"


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

    <Button
        android:id="@+id/button1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Pavan"
        android:textSize="30dp" />

</LinearLayout>



3. View With
             android:layout_width="wrap_content"
             android:layout_height="fill_parent"


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

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:text="Pavan"
        android:textSize="30dp" />

</LinearLayout>



4. View With
             android:layout_width="fill_parent"
             android:layout_height="fill_parent"


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

    <Button
        android:id="@+id/button1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:text="Pavan"
        android:textSize="30dp" />

</LinearLayout>


Read More »