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!
- ERROR x86 emulation currently requires hardware acceleration. Intel HAXM is not installed on this machine
- How to create Toast messages in Android?
- Java: Check Internet connection on Android Device (Wifi or Mobile)
- Change Title text for Android Activity using java code
- Android RatingBar Example
- Android : Execute some code after back button is pressed
- Audio Video Network protocols supported by Android OS Devices
- This class should be public (android.support.v7.internal.widget.ActionBarView.HomeView) Lint Error
- Check Internet Connection WIFI 4G is active on Android Programmatically
- Change Height of Android ActionBar
- Generate Facebook Android SDK keyhash using java code
- How to hide or cancel Toast message in Android Programming
- Make Android Toolbar text center aligned
- How to Disable EditText Keyboard Android App
- How to repeat background image in Android Activity
- How to make Android EditText not editable
- [FIX] AndroidRuntime: FATAL EXCEPTION: main - java.lang.RuntimeException NullPointerException
- Android Eclipse This version of the rendering library is more recent than your version of ADT plug-in. Please update ADT plug-in
- How to Add a horizontal line in Android Layout
- Android Disable back button programatically
- 21 Useful Android Emulator Short-cut Keyboard Keys
- Android xml error Attribute is missing the Android namespace prefix [Solution]
- Fixing Android unknown error 961 while downloading app
- Share Image and Text on Instagram from Android App using Share Dialog
- How to add border to Android Button
- [Android Studio] failed to find Build Tools revision 23.0.0 rc1 - Android-Studio
- How to ls command to output one entry per line [macOS/Linux/Bash] - Linux
- Android Display Toast on Button Click - Android
- Eclipse: Updating Maven Project. Unsupported IClasspathEntry kind=4 - Eclipse
- How to do calculations in Mac Terminal - MacOS