What's the correct way to pass a bundle to the activity that is being launched from the current one? Shared properties?
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
You can pass values from one activity to another activity using the Bundle. In your current activity, create a bundle and set the bundle for the particular value and pass that bundle to the intent.
Now in your NewActivity, you can get this bundle and retrive your value.
You can also pass data through the intent. In your current activity, set intent like this,
Now in your NewActivity, you can get that value from intent like this,
Passing data from one Activity to Activity in android
An intent contains the action and optionally additional data. The data can be passed to other activity using intent
putExtra()
method. Data is passed as extras and arekey/value pairs
. The key is always a String. As value you can use the primitive data types int, float, chars, etc. We can also passParceable and Serializable
objects from one activity to other.Retrieving bundle data from android activity
You can retrieve the information using
getData()
methods on the Intent object. The Intent object can be retrieved via thegetIntent()
method.You have a few options:
1) Use the Bundle from the Intent:
2) Create a new Bundle
3) Use the putExtra() shortcut method of the Intent
Then, in the launched Activity, you would read them via:
NOTE: Bundles have "get" and "put" methods for all the primitive types, Parcelables, and Serializables. I just used Strings for demonstrational purposes.
Write this is the activity you are in:
In the NextActivity.java
This works for me, you can try it.
Source:https://www.c-sharpcorner.com/article/how-to-send-the-data-one-activity-to-another-activity-in-android-application/
You can use the Bundle from the Intent:
Or an entire bundle:
Is this what you're looking for?