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!
- 21 Useful Android Emulator Short-cut Keyboard Keys
- Android Development - How to switch between two Activities
- Download interrupted: Unknown Host dl-ssl.google.com Error Android SDK Manager
- Android : java.lang.IllegalArgumentException File contains a path separator
- Programmatically Send an Email from Android App using Intent
- How to make a Android button act as a toggle button
- The Android Virtual Device is currently running in an emulator and cannot be deleted
- How to add Back Button on Toolbar in Android [Tutorial]
- Change Height of Android ActionBar
- How to change TextView or EditText Text Color on Focus and on Press
- How to create Toast messages in Android?
- Create Custom Toast Android Programming
- Center align text in TextView Android Programming
- Create Custom Android AlertDialog
- Disable Fading Edges Scroll Effect Android Views
- Change Title text for Android Activity using java code
- Android-Failed to install apk on device EOF Timeout Error
- Fixed Length Android Edittext
- Programmatically check if Facebook is installed on Android device
- Generate Facebook Android SDK keyhash using java code
- Change Android Toast background color
- This class should be public (android.support.v7.internal.widget.ActionBarView.HomeView) Lint Error
- AlertDialog with image using ImageView Example
- How to take a screenshot of android emulator (AVD) screen
- Android EditText Cursor Colour appears to be white
- How to check if Java main thread is alive - Java
- Possible outages message Google Webmaster tool - Google
- Sublime Text 3 spell check shortcut - Sublime
- [Error] zsh: command not found: mvn - HowTos
- How to Gzip a file directory on Mac OS X using Terminal Command - Mac-OS-X
- How to un-hide tab bar in notepad++ - NotepadPlusPlus
- Failed to load the JNI shared library jvm.dll - Eclipse
- Hotstar Disney+ mobile app test push notification - News
- Display bookmarks bar Safari - HowTos
- SharePoint Server 2016 installation System Hardware requirements - SharePoint
- How to check your IP using bash for Windows? - Bash
- Eclipse Error The JVM Shared Library JavaVirtualMachines does not contain the JNI_CreateJavaVM symbol - Eclipse
- Changing Android Intent Tittle using java code - Android
- How to send SMS on Android Emulator - Android
- How to check if a port is in use using terminal [Linux or macOS] - MacOS
- Install Native Java JDK JRE on Apple Silicon M1 Mac - MacOS
- Create SharePoint Site Collection using PowerShell New-SPSite - SharePoint