Andriod Program – Intent Action

ANDROID FOR FRESHERS

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:

intent action java source code snippets  intent action java source code snippets

Intent action java source code snippets

Download Intent Action source Code

For More Android Programs –Click Here

 

Follow Us – Never Miss Update

Fb/PageTwitterGoogle+InstagramPinterest 

Related Search

Android Intent action snippet source code download, android intent program code download, android intent code download, intent action example download, intent action java code snippet, intent action java source code snippets, intent action android, android intent example programs

Leave a Comment

Comments

No comments yet. Why don’t you start the discussion?

    Comments