Home > Android > Explicit Intent In Android | Switching With Data

Explicit Intent In Android | Switching With Data

Explicit Intent In Android

 

An intent is abstract used with startActivity to launch/start an Activity, broadcastIntent to send it to any interested BroadcastReceiver components.

startService(Intent) or bindService(Intent, ServiceConnection, int) is used to  communicate with a background Service.

Standard Action performed using Intents for launching activities ie., usually startActivity(Intent)

ACTION_MAIN

ACTION_VIEW

ACTION_ATTACH_DATA

ACTION_EDIT

ACTION_PICK

ACTION_CHOOSER

ACTION_GET_CONTENT

ACTION_DIAL

ACTION_CALL

ACTION_SEND

ACTION_SENDTO

ACTION_ANSWER

ACTION_INSERT

ACTION_DELETE

ACTION_RUN

ACTION_SYNC

ACTION_PICK_ACTIVITY

ACTION_SEARCH

ACTION_WEB_SEARCH

ACTION_FACTORY_TEST

Intent are used for two types, Switching with Data and Switching without data. Here an example for Intent switching with Data.

Scenario :

User entered his/her Name in first Activity. We have to read the user input data(Name) and should display in user data(Name) in next screen (Activity). 

   

Explicit Intent In Android

 

(Switching With Data)

Java Code(Intent2)

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

public class Intent2 extends Activity {
EditText et1;

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

Java Code (Intent2Next)

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

public class Intent2Next extends Activity {
TextView tv1;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_intent2_next);
tv1 = (TextView) findViewById(R.id.tv5);
Intent i = getIntent();
Bundle b = i.getExtras();
String name = b.getString(“k1”);
tv1.setText(“Welcome ” +name);

}

}

Layout XML Code(activity_intent2)

<?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.Intent2″>

<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/intentstext”
android:layout_marginBottom=”120dp” />

<EditText
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:id=”@+id/et1″
android:hint=”Enter Your Name”
android:layout_marginBottom=”20dp”/>

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

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

</LinearLayout>

Layout XML Code(activity_intent2_next)

<?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:gravity=”center”
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.Intent2Next”>

<TextView
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:id=”@+id/tv5″
android:text=” “
android:textColor=”@color/four”
android:textSize=”20dp”
android:textStyle=”bold”/>

</LinearLayout>




Output : 

   

Download Source Code

Learn Android 

Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api' It will be removed at the end of 2018

Configuration ‘compile’ is obsolete and has been replaced with ‘implementation’ and ‘api’

Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api' It will be ...
Read More

Android Fragment Example | Whatsapp Model

ANDROID Android Fragment Example Android Fragment Example : Fragment Activity Android Program of fragment sample ...
Read More
Android Intent Service

Android Intent Service | Phone Vibration

Android Intent Service ANDROID Android Program of Android Intent Service (Vibrate) Activity: Making Phone to ...
Read More

Explicit Intent In Android | Switching With Data

Explicit Intent In Android An intent is abstract used with startActivity to launch/start an Activity, ...
Read More
Explicit Intent In Android

Explicit Intent In Android | Switching Without Data

Explicit Intent In Android Android Program of Explicit Intent In Android (Switching Without Data)     Java ...
Read More
Android Sqlite Database Example

Android Sqlite Database Example | Source Code

ANDROID Android Sqlite Database Example Android Sqlite Database Example     Java Code(SQLiteAct) import android.app.Activity; ...
Read More
Android Button onclick

Android Button onclick | Event Handler

ANDROID Android Button onclick Android Button onclick | Event Handler             ...
Read More

Android Program – Navigation Drawer

ANDROID Android Program - Navigation Drawer       Java Code(NavAct) import android.app.Activity; import android.content.Intent; ...
Read More

Android Program – Wifi Activity

ANDROID Android Program - Wifi Activity          Java Code(WifiAct) import android.app.Activity; import ...
Read More

Android Program – Drawable shape resource

ANDROID Android Program of Drawable shape resource Java Code(ShapeAct) import android.app.Activity; import android.content.Intent; import android.os.Bundle; ...
Read More

Android Program – Email Activity

ANDROID Android Program - Email Activity         Java Code(EmailAct) import android.app.Activity; import ...
Read More

Android Program – Options Menu

ANDROID Android Program - Options Menu           Java Code(OptionAct) import android.content.Intent; ...
Read More

Android Program – Context Menu

ANDROID Android Program - Context Menu      Java Code(ContextAct) import android.app.Activity; import android.content.Intent; import ...
Read More

Android Program – Notification Activity

ANDROID Android Program of Notification Activity     Java Code(NotificationAct) import android.app.Activity; import android.app.Notification; import ...
Read More
Android Seekbar Example

Android Seekbar Example | Source Code

Android Seekbar Android Seekbar Example    Java Code(SeekAct) import android.app.Activity; import android.content.Intent; import android.os.Bundle; import ...
Read More
Android Ratingbar

Android Ratingbar | Source Code

 Android Ratingbar  Android Ratingbar | Source code    Java Code(RatingAct ) import android.app.Activity; import android.content.Intent; ...
Read More
Android Radio Button Example

Android Radio Button | Snippet | Source Code

 Android Radio Button  Android Radio Button Example:         Java Code(RadioAct) import android.app.Activity; ...
Read More

Android Program -Touch Activity

ANDROID Android Program -Touch Activity     Java Code(TouchAct ) import android.app.Activity; import android.content.Intent; import android.graphics.Color; ...
Read More

Android Program – Time Picker Activity

ANDROID Android Program - Time Picker Activity      Java Code(TimeAct) import android.app.Activity; import android.app.Dialog; ...
Read More

Android Program – Date Activity

ANDROID Android Program - Date Activity       Java Code(DateAct)  import android.app.Activity; import android.app.DatePickerDialog; ...
Read More

Android Program – Audio Player Activity

ANDROID Android Program - Audio Player Activity Java Code(AudioAct) import android.app.Activity; import android.content.Intent; import android.os.Bundle; ...
Read More

Android Program – Call Dial Activity

ANDROID  Android Program of Call Dial Activity    Java Code(DialAct ) import android.app.Activity; import android.content.Intent; ...
Read More

Android Program – Camera Activity

ANDROID  Android Program of Camera Activity Java Code(CameraAct) import android.app.Activity; import android.content.Intent; import android.provider.MediaStore; import ...
Read More
Android Alertdialog Example

Android Alertdialog Example

Android Alertdialog Example Android Alertdialog Example    Java Code (AlertDialogAct) import android.app.Activity; import android.content.DialogInterface; import ...
Read More
Android Spinner Example

Android Spinner Example

Android Spinner  Android Spinner Example     Java Code(SpinnerAct) import android.app.Activity; import android.content.Intent; import android.os.Bundle; ...
Read More
Android Listview Example

Android Listview Example

Android Listview   Android Listview Example      Java Code(ListViewAct) import android.app.Activity; import android.content.Intent; import android.os.Bundle; ...
Read More
Android Checkbox Example

Android Checkbox Example

ANDROID Android Checkbox Example    Java Code(CheckBoxAct) import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; ...
Read More
Toast Example In Android

Android Program – Toast Activity

Toast Example In Android Toast Example In Android     Java Code(ToastAct ) import android.app.Activity; ...
Read More

Andriod Program – Intent Action

ANDROID Android program for Intent Action        Java Code(MainAct)  import android.app.Activity; import android.content.Intent; ...
Read More
Android Interview Questions For Freshers

Android Interview Questions For Freshers

 Android Interview Questions For Freshers Android Interview Questions For Freshers | Experience How many activity ...
Read More

What’s More in FDAYTALK ?

 

Follow Us – Never Miss Update

Fb/PageTwitterGoogle+InstagramPinterest 


[metaslider id=3165]

Recent   

Explicit Intent In Android – Android app development course for beginners 

Is this Useful content For You?