• Home
  • WordPress
  • web Hosting
  • linux
  • mysql
  • nginx
  • apache2
  • devops

Raju Ginni

wordpress tutorials seo hosting etc

You are here: Home / tutorials / Android Studio tutorials syllabus Topics Course details #AndroidApplicationDevelopment / intent with Data

intent with Data

The intent with Data:
To send data from one Activity to another Activity, we use Intent class object. This includes some set of steps in source activity and some steps in-destination activity.

Steps to send data from Source Activity:
1) Create Intent object by providing source activity and destination activity
Intent i = new Intent(source activity.this, destination activity.class);
2) Attach data to Intent. We use putExtra method of Intent to attach data. This method takes 2 parameters. One is key and the other is value. We use the same keys to retrieve data in destination activity.
To send following values to destination activity,
123
false
c
Naresh IT

i.putExtra(“key1”, 123);
i.putExtra(“key2”, false);
i.putExtra(“key3”, ‘c’);
i.putExtra(“key4”, “Naresh IT”);
3) call startActivity method

startActivity(i);

Altogether,
Intent i = new Intent(SourceActivity.this, DestinationActivity.class);
i.putExtra(“key1”, 123); // Passing int data
i.putExtra(“key2”, false); // Passing boolean data
i.putExtra(“key3”, ‘c’); // Passing char data
i.putExtra(“key4”, “Naresh IT”); // Passing String data
startActivity(i);

Retrieving the data in DestinationActivity:
1) Get the Intent
Intent i = getIntent();
2) Get the data bundle associated to Intent
Bundle b = i.getExtras();
3) Retrieve individual values from Bundle by providing keys
int data1 = b.getInt(“key1”);
boolean data2 = b.getBoolean(“key2”);
char data3 = b.getChar(“key3”);
String data4 = b.getString(“key4”);

 

Create an android application to describe Intent with Data

XML:
activity_first.xml:
<?xml version=”1.0″ encoding=”utf-8″?>
<LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android”
android:layout_width=”match_parent”
android:layout_height=”match_parent”
android:gravity=”center”
android:orientation=”vertical”>
<Button
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:onClick=”sendData”
android:text=”Send data” />
</LinearLayout>

activity_second.xml:
<?xml version=”1.0″ encoding=”utf-8″?>
<LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android”
android:layout_width=”match_parent”
android:layout_height=”match_parent”
android:gravity=”center”
android:orientation=”vertical”>
<TextView
android:id=”@+id/text_result”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:textSize=”25sp”
android:textStyle=”bold” />
</LinearLayout>

 

Java:
FirstActivity.class

public class FirstActivity extends Activity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_first);
}

public void sendData(View v){
Intent i = new Intent(FirstActivity.this, SecondActivity.class);
i.putExtra(“key1”, 123); // Passing int data
i.putExtra(“key2”, false); // Passing boolean data
i.putExtra(“key3”, ‘c’); // Passing char data
i.putExtra(“key4”, “Naresh IT”); // Passing String data
startActivity(i);
}
}

SecondActivity.class:
public class SecondActivity extends Activity {
TextView textResult;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
textResult = (TextView) findViewById(R.id.text_result);

Intent intent = getIntent();
Bundle bundle = intent.getExtras();
int data1 = bundle.getInt(“key1”);
boolean data2 = bundle.getBoolean(“key2”);
char data3 = bundle.getChar(“key3”);
String data4 = bundle.getString(“key4″);
String result = data1 + ” ” + data2 + ” ” + data3 + ” ” + data4;
textResult.setText(result);
}
}

AndroidManifest.xml:
Inside <application> tag,

<activity android:name=”.FirstActivity”>
<intent-filter>
<action android:name=”android.intent.action.MAIN” />
<category android:name=”android.intent.category.LAUNCHER” />
</intent-filter>
</activity>

<activity android:name=”.SecondActivity” />

 

HW: Create an android application with one EditText and Button in first activity. On clicking the button, get the data from EditText and send it to second activity show in a TextView.

 

 

 

tutorials

  • Core Java Tutorial Free online
  • HTML & CSS Tutorials
  • Php tutorials
  • ubuntu tutorials installation download issues etc
  • redis install ubuntu 20.04 with wordpress php redis mysql configuration
  • [INTRO] Ethical hacking / cyber Security / Penetration testing Tutorial -{updates frequently}
  • Android Studio tutorials syllabus Topics Course details #AndroidApplicationDevelopment
    • Options Menu
    • JSON parsing
    • Handling Views
    • RelativeLayout
    • ActionBar
    • ListView
    • Custom List View
    • Dialogs
    • AlarmManager
    • Notifications
    • Vibration
    • WebView
    • Fragments Runtime
    • SQLiteDatabase
    • Bluetooth
    • WiFi
    • Google Maps
    • Handling Activity Back Button
    • AsyncTask
    • Runtime Permissions
    • Logging
    • Activity Lifecycle
    • Toast
    • Service
    • Database with Cursor Adapter
    • SharedPreferences
    • Location
    • Libraries
    • Webservices
    • Creating Activity class
    • Creating XML
    • Registering Activity in AndroidManifest.xml:
    • Steps for creating an Android application:
    • Handling button clicks
    • Identifying Views
    • Getting Text from Views
    • intent with Data
    • Intent
    • Resources Handling in Android
    • Intent with Result Data
    • Broad cast Receiver
    • Fragment
    • Handling Button click by using On Click Listener:
    • Material Design
    • RecyclerView
    • JSON
    • Rename Android Package [with images & video 2020]
    • migrating to androidx (The library & dependency matching)
    • adsense on webview , adsense & admob policies & implementation
  • AUdio Editing Background Noise removal (Audacity, Adobe Premiere Addition, Camtasia Filmora Windows Obs)
  • what is vpn vs proxy vs tor, http vs https, http2, tcp vs udp, kali linux sql source code injection
  • how to create a website free of cost on google
  • CCNA Syllabus pdf (CCNA / CCNP vs devops vs mcsa /MCSE)
  • Redis performance metrics & tuning for nginx apache ubuntu & debian
  • xampp tutorials 2021 installation errors fix wordpress phpmyadmin mysql apache
  • new relic installation linux (infrastructure agent , php, mysql , nginx)
  • new relic mysql install integration - 2 ways fix problems
  • new relic php agent install in 3 steps
  • aws load balancer tutorial
  • git branches merge fetch pull conflicts

hi i am raju ginni, primalry i manage wordpress websites on GCP cloud platform as a cloud engineer, and create content on passionate things.
you can follow me on youtbe

© 2025 - All Rights Reserved Disclaimer & Privacy Policy