If you are new to Android App Development and understand how an Activity works, the next thing that will come to your mind is "How to switch from one Activity to another based on an action - such as button click?"
Let's see a code example of how you can do that!
Let's say you have created a second activity with the name MySecondActivity.java, to open this activity you would need to add the blow line of code on your method where the action is performed,
How to pass data from one Activity to another?
Intent indent = new Intent(getApplicationContext(), MySecondActivity.class); startActivity(indent);
Now that you know how to call one activity from another using Indent, let's see how we can pass data just like we can do using an HTTP GET/Post request,
How to read the data from one Activity to another?
Intent indent = new Intent(getApplicationContext(), MySecondActivity.class); indent.putExtra("key","value"); indent.putExtra("key1,"value1"); startActivity(indent);
Now that we know how to send data from one activity to other, let's see how the other activity can read that passed data!
Intent intent = getIntent(); String data = indent.getStringExtra("key"); String data1 = indent.getStringExtra("key1"); startActivity(indent);
Have Questions? Post them here!
- Android : Duplicate registration for activity com.example.abc
- Get Wifi Details : Android Programming
- How To Disable Landscape Mode in Android Application
- Detect Data roaming in Android Application
- Changing Android Intent Tittle using java code
- Programmatically Send an Email from Android App using Intent
- java.lang.NoClassDefFoundError android.support.v4.content.LocalBroadcastManager
- Make Android View Scrollable both Horizontally and Vertically
- Force android app to run in Landscape mode programatically
- How to display Toast in a thread : Android
- 21 Useful Android Emulator Short-cut Keyboard Keys
- Android Wifi WPA2/WPA Connects and Disconnects issue
- How to set background color for android layout pragmatically using java and through xml
- The Android Virtual Device is currently running in an emulator and cannot be deleted
- SQLite Error: unknown command or invalid arguments: open. Enter .help for help
- incorrect line ending: found carriage return (\r) without corresponding newline (\n)
- The declared package does not match the expected package Eclipse
- Center Align TextView Android Horizontally or Vertically
- Android Development - How to switch between two Activities
- Android AlertDialog with Yes No and Cancel Button
- Android Error Unexpected cast to Button: layout tag was FrameLayout
- Maven : java.lang.ClassNotFoundException: Xmx512m
- Android-Failed to install apk on device EOF Timeout Error
- Unable to load VM from snapshot. The snapshot has been saved for a different hardware configuration
- Use 5G Network on Android Emulator
- Open Docker from Terminal Command on Mac - MacOS
- How to fix Java HTTP java.net.UnknownHostException - Java
- Android : No Launcher activity found! Error - Android
- Show Hide SharePoint column in List Library form with the conditional formula - SharePoint
- How to Stop/Cancel/kill docker image pull - Docker
- Reading .xls and .xlsx Excel file using Apache POI Java Library - Java
- Permanently set $PATH variable in Mac Zsh shell - MacOS
- SharePoint Server 2016 error - Failed to connect to the configuration database - SharePoint