Wednesday, 21 November 2012

Intent Demo 1

Demo:

 

1.First Screen Activity:


package com.venkool;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class IntentDemoActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.first);
       
        Button btnClick = (Button) findViewById(R.id.btnMove);
       
        btnClick.setOnClickListener(new OnClickListener() {
                 
                  @Override
                  public void onClick(View v) {

                        Intent intent = new Intent(IntentDemoActivity.this,SecondScreen.class);
                        startActivity(intent);
                  }
            });
    }
}

2)Second Activity:


package com.venkool;

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

public class SecondScreen extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.second);
    }
}


3)first.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/myBackground"
    android:orientation="vertical" >

    <TextView
        android:layout_marginTop="10dp"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="First Screen"
        android:textSize="25dp"
        android:textStyle="bold" />

    <Button
        android:id="@+id/btnMove"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="90dp"
        android:gravity="center"
        android:text="Move to Next Screen" />

</LinearLayout>


4)second.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:background="@color/myFrontEnd">

    <TextView
        android:layout_marginTop="10dp"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="Second Screen"
        android:textSize="25dp"
        android:textStyle="bold" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="90dp"
        android:gravity="center"
        android:text="Welcome! Its Second Screen"
        android:textSize="20dp"/>

</LinearLayout>


5)Register your Activity in manifest.xml:


  
<activity
            android:label="@string/app_name"
            android:name=".SecondScreen" />


6)Download this Project Click Here
 

No comments:

Post a Comment