Explicit Intent In Android | Switching With Data

Explicit Intent Program In Android

Android Programs For Beginners

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 of Explicit Intent In Android

Learn Android

Link1 – Complete Android Programs with Source Code Download

Link 2- Android Interview Questions for Freshers and Beginners

Link 3- MNC’s Jobs Vacancies 2018 

Link 4- Java Interview Questions for Freshers and Experience

Explicit Intent program source code download Android #AndroidForBeginners

Related Search

Android app development course for beginners, android application development for dummies, android developer intent, android intent example for beginners, android intent activity source code download, android intent example with source code, android intent putextra example, android new activity example and code, android programming for beginners with source code download for beginners, what is android start activity, android start new activity example, android studio intent example code, app development course for beginners, beginning android application development, explicit intent example for beginners source code, Explicit Intent In Android code for freshers, getintent android, getting started with android programming, android studio, intent filter, intent filter in android, java android example in java code, java android tutorial for beginners download, learning android programming for beginners download, new intent example code, putextra code in java, putextra android java code, startactivity intent java code example, startactivityforresult example for beginners, #AndroidForBeginners, AndroidForBeginners, Explicit Intent source code download Android

Comments

10 Best Building Games on PC in 2024 Review: Why Buy Lava Blaze Curve 5G? Sale is Live! Review: Why Buy boAt Stone Spinx Pro? New Portable Speaker Xiaomi 14 Series Debuts in India, starting at ₹59,999 Best Wireless TWS Earbuds: Up to 75% Off Deals