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 Error Unexpected cast to Button: layout tag was FrameLayout
- ADT quit unexpectedly error on Mac OSX Android Eclipse SDK
- Parsing Data for android-21 failed unsupported major.minor version 51.0
- Android Studio Ctrl Shift o auto import not working
- java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
- Android : How to make TextView Scrollable
- This class should be public (android.support.v7.internal.widget.ActionBarView.HomeView) Lint Error
- Integrating Android Facebook SDK 3.17.2 Tutorial
- Android R Cannot Be Resolved To A Variable
- Android : Exception raised during rendering: action_bar API 22
- How to take screenshot on Android
- Read Text file from SD Card : Android Programming
- How to make Android EditText not editable
- Your Android SDK is out of date or is missing templates. Please ensure you are using SDK version 22 or later.
- The declared package does not match the expected package Eclipse
- Can't Run SDK Manager find_java.bat issue
- What is Android Toast.LENGTH_SHORT and Toast. LENGTH_LONG durations
- Android Emulator Soft Back button action using Computer keyboard
- Multiline EditText in Android Example
- Use 5G Network on Android Emulator
- Make Android TextView Clickable like Buttons
- How to empty trash in Android Device
- Android : Execute some code after back button is pressed
- Disable Fading Edges Scroll Effect Android Views
- How To Disable Landscape Mode in Android Application
- CSS: Apply opacity only for div background and not text - CSS
- fix fatal: --local can only be used inside a git repository error - Git
- Android read text file from internal storage - Android
- WhatsApp launches WhatsApp Web to Access Messages over web browser - WhatsApp
- #HappyBirthdayJimin trending Happy Birthday Jimin BTS Army - BTS
- Set Title to Android AlertDialog - Android
- Set Python 3.8 as a default python version on macOS - MacOS
- 10 Beginners Commands for macOS Terminal Usage - MacOS