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,
Intent indent = new Intent(getApplicationContext(), MySecondActivity.class);
startActivity(indent);
How to pass data from one Activity to another?
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,
Intent indent = new Intent(getApplicationContext(), MySecondActivity.class);
indent.putExtra("key","value");
indent.putExtra("key1,"value1");
startActivity(indent);
How to read the data from one Activity to another?
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);
Related post: https://code2care.org/q/pass-data-between-two-activities-intent
![How to switch between two Activities How to switch between two Activities](https://code2care.org/tutorial/android-switch-between-two-activities/images/How to switch between two Activities.png)
Have Questions? Post them here!
- Increase Android Emulator Timeout time
- Android : Remove ListView Separator/divider programmatically or using xml property
- Error : Invalid key hash.The key hash does not match any stored key hashes
- How to Change Android Toast Position?
- Android Alert Dialog with Checkboxes example
- Android : No Launcher activity found! Error
- Android Development: Spinners with Example
- Failed to sync Gradle project Error:failed to find target android-23
- INSTALL_FAILED_INSUFFICIENT_STORAGE Android Error
- Disable Fading Edges Scroll Effect Android Views
- How to create Toast messages in Android?
- Channel 50 SMSes received every few minutes Android Phones
- Android xml error Attribute is missing the Android namespace prefix [Solution]
- Create Custom Android AlertDialog
- How To Disable Landscape Mode in Android Application
- Android Development - How to switch between two Activities
- incorrect line ending: found carriage return (\r) without corresponding newline (\n)
- Generate Facebook Android SDK keyhash using java code
- Android Error Generating Final Archive - Debug Certificate Expired
- 21 Useful Android Emulator Short-cut Keyboard Keys
- Android RatingBar Example
- 11 Weeks of Android Online Sessions-15-Jun-to-28-Aug-2020
- Download interrupted: Unknown Host dl-ssl.google.com Error Android SDK Manager
- fill_parent vs match_parent vs wrap_content
- Android : Connection with adb was interrupted 0 attempts have been made to reconnect
- How to check RAM details on Mac? - MacOS
- How to change the font in TextEdit on Mac - MacOS
- How to install Rust using rustup on macOS/Linux/Ubuntu - Rust
- How to stop disable Facebook video autoplay during scroll - Facebook
- How to add Colors to VIM (syntax highlighting) - vi
- Python: How to create a Panda Data frame from a List - Python
- How to get current URL Location using Javascript HTML - JavaScript
- Copy entire directory using Terminal Command [Linux, Mac, Bash] - Linux