Home > Android > Andriod Program – Intent Action

Andriod Program – Intent Action

ANDROID



Android program for Intent Action

      

Java Code(MainAct) 

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

public class MainAct extends Activity {
EditText et1; 

  @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
et1=(EditText)findViewById(R.id.et1);
}
public void next(View v)
{
String name=et1.getText().toString().trim();
Intent i=new Intent(MainAct.this,NextAct.class);
i.putExtra(“k1”,name);
startActivity(i);
}

}

Java Code(NxtAct Activity) 

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.LinearLayout;
import android.widget.TextView;

public class NextAct extends Activity {
TextView tv;
LinearLayout l1;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_next2);
l1=(LinearLayout)findViewById(R.id.l1);
tv=(TextView)findViewById(R.id.tv);
Intent i=getIntent();
Bundle b= i.getExtras();
String name= b.getString(“k1”);
tv.setText(name);

}
}

Layout XML Code(activity_main2)

<?xml version=”1.0″ encoding=”utf-8″?>
<LinearLayout 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”
android:orientation=”vertical”
android:paddingBottom=”@dimen/activity_vertical_margin”
android:paddingLeft=”@dimen/activity_horizontal_margin”
android:paddingRight=”@dimen/activity_horizontal_margin”
android:paddingTop=”@dimen/activity_vertical_margin”
tools:context=”com.andro.tech.androidproject.MainAct”>

<TextView
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:textSize=”@dimen/textsize”
android:layout_gravity=”center”
android:textStyle=”bold”
android:text=”@string/maintext”
android:layout_marginBottom=”120dp” />

<EditText
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:gravity=”center”
android:hint=”Enter Text”
android:id=”@+id/et1″
android:layout_marginBottom=”30dp”/>

<Button
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:text=”Next Activity”
android:onClick=”next”
android:layout_marginBottom=”110dp”/>

<Button
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:text=”@string/sourcecode”
android:background=”@color/bgcolor”
android:textStyle=”bold”
android:layout_gravity=”bottom”
android:textColor=”@color/text”
android:onClick=”view1″/>

</LinearLayout>

 Layout XML Code(activity_next2)

<LinearLayout 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”
android:orientation=”vertical”
android:gravity=”center”
android:id=”@+id/l1″
android:paddingBottom=”@dimen/activity_vertical_margin”
android:paddingLeft=”@dimen/activity_horizontal_margin”
android:paddingRight=”@dimen/activity_horizontal_margin”
android:paddingTop=”@dimen/activity_vertical_margin”
tools:context=”com.andro.tech.androidproject.NextAct”>

<TextView
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:text=” “
android:id=”@+id/tv”
android:gravity=”center”
android:textStyle=”bold”
android:textSize=”@dimen/textsize”
android:textColor=”@color/four”/>

 

</LinearLayout>


Output :

  

Download source Code




Follow Us – Never Miss Update

Fb/PageTwitterGoogle+InstagramPinterest 

Recent   

[metaslider id=3165]


Is this Useful content For You?