Friday, 20 March 2015

About Me

{
"name": "Nadavati Siva"
"roles": [ "Molibe app  Developer", "Designer", "Engineer" ]
"city": "Bangalore"
"Phone Number": "8951283077"
"Email": "Nadavati.siva776@gmail.com"
"social": [ "Github", "Facebook", "Twitter" ]
}

Monday, 9 December 2013

Android Activity – From One Screen To Another Screen

In Android, an activity is represent a single screen. Most applications have multiple activities to represent different screens, for example, one activity to display a list of the application settings, another activity to display the application status.

Note
Refer to this official Android activity article to understand more about Android activity.

In this tutorial, we show you how to interact with activity, when a button is clicked, navigate from current screen (current activity) to another screen (another activity).

1. XML Layouts
Create following two XML layout files in “res/layout/” folder :
  1. res/layout/main.xml – Represent screen 1
  2. res/layout/main2.xml – Represent screen 2
File : res/layout/main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/linearLayout1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
 
    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="I&apos;m screen 1 (main.xml)"
        android:textAppearance="?android:attr/textAppearanceLarge" />
 
    <Button
        android:id="@+id/button1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Click me to another screen" />
 


File : res/layout/main2.xml


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/linearLayout1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >
 
    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="I&apos;m screen 2 (main2.xml)"
        android:textAppearance="?android:attr/textAppearanceLarge" />
 

2. Activities Create two activity classes : 

 AppActivity.java –> main.xml App2Activity.java –> main2.xml To navigate from one screen to another screen, use following code :

Intent intent = new Intent(context, anotherActivity.class);
    startActivity(intent);

File : AppActivity.java

package com.nadavatisiva.android;
 
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.view.View;
import android.view.View.OnClickListener;
 
public class AppActivity extends Activity {
 
 Button button;
 
 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);
  addListenerOnButton();
 }
 
 public void addListenerOnButton() {
 
  final Context context = this;
 
  button = (Button) findViewById(R.id.button1);
 
  button.setOnClickListener(new OnClickListener() {
 
   @Override
   public void onClick(View arg0) {
 
       Intent intent = new Intent(context, App2Activity.class);
                            startActivity(intent);   
 
   }
 
  });
 
 }
 
}


File : App2Activity.java

package com.nadavatisiva.android;
 
import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
 
public class App2Activity extends Activity {
 
 Button button;
 
 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main2);
 }
 
}

3. AndroidManifest.xml

 Declares above two activity classes in AndroidManifest.xml. 

File : AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.nadavatisiva.android"
    android:versionCode="1"
    android:versionName="1.0" >
 
    <uses-sdk android:minSdkVersion="10" />
 
    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:label="@string/app_name"
            android:name=".AppActivity" >
            <intent-filter >
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:label="@string/app_name"
            android:name=".App2Activity" >
        </activity>
    </application>
 
</manifest>

4. Demo 

Run application.

AppActivity.java (main.xml) screen is display.


When above button is clicked, it will navigate to another screen App2Activity.java (main2.xml)



If you have any doubts or suggestions, please place them in the comments.

Thanks happy coding :-)






Sunday, 8 December 2013

Android Hello World Example

In this tutorial, we show you how to create a simple “hello world” Android project in Eclipse IDE + ADT plugin, and run it with Android Virtual Device (AVD). The Eclipse ADT plugin provided easy Android project creation and management, components drag and drop, auto-complete and many useful features to speed up your Android development cycles.


Summary steps to develop an Android application :
  1. Install Android SDK
  2. Install ADT Eclipse plugin
  3. Create an Android Virtual Device (AVD)
  4. Create Android Project with Eclipse (Wizard)
  5. Code it…
  6. Start it in Android Virtual Device (AVD)
Tools used in this tutorial :
  1. JDK 1.6
  2. Eclipse IDE 3.7 , Indigo
  3. Android SDK

1. Install Android SDK

Visit this Android SDK page, choose which platform and install it.
In Android SDK installed folder, run “Android SDK manager”, choose what Android version you want to develop.




2. Install ADT Eclipse plugin
To integrate Android SDK with Eclipse IDE, you need to install Eclipse ADT plugin. Refer to this official guide – “Installing the ADT Plugin“.
In Eclipse IDE, select “Help” -> Install New Software…”, and put below URL :
https://dl-ssl.google.com/android/eclipse/



Note
In my case, above ADT plugin is taking years to download, no idea why. If you are facing the similar problem, just download and install the ADT plugin manually, refer to this ADT plugin troubleshooting guide.

3. Create an Android Virtual Device (AVD)

In Eclipse, you can access the “Android Virtual Device (AVD)” in Eclipse toolbar. Click “new” to create a AVD.

Later, Eclipse will deploy the application into this AVD.

4. Create Android Project
In Eclipse, select “File -> New -> Project….”, “Android Project”, and input your application detail. Eclipse will create all the necessary Android project files and configuration.

5. Hello World

Locate the generated activity file, and modify a bit to output a string “Hello World”.
File : MainActivity.java


package com.nadavatisiva.helloworld;
 
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
 
public class MainActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
 
        TextView text = new TextView(this);
        text.setText("Hello World, Android -  http://nadavatisivasofttech.blogspot.in/");
        setContentView(text);
    }
}

6. Demo

Run it as “Android Application“, see output.
Press “Home” button (on right hand side), and you will noticed that “HelloWorld” application is deployed successfully on the Android virtual device.
Note
This tutorial is more to example driven, not much explanation. For detail and complete explanation, please refer to the official Android developer hello world tutorial.
Thanks happy coding enjoy :-)

Started using my own blog

Hello All,

Started using my own blog:-)