How to send more than 1 data with bundle ?
If only one :
String status = txtStatus.getText().toString();
String txtstatus = String.valueOf(status);
Bundle bundle = new Bundle();
bundle.putString("status", txtstatus);
a.putExtras(bundle);
startActivityForRe开发者_如何学编程sult(a, 0);
if more than 1 data ??
String status = txtStatus.getText().toString();
String txtstatus = String.valueOf(status);
String confirm = txtConfirm.getText().toString();
String txtconfirm = String.valueOf(confirm);
what's next ??
just keep adding in bundle
as you are adding bundle.putString("status", txtconfirm );
and when you are done set this bundle to intent:a.putExtras(bundle);
If I understood the question, this should be fine:
Bundle bundle = new Bundle();
bundle.putString("status", txtstatus);
bundle.putString("confirm", txtconfirm);
for more than one data
String status = txtStatus.getText().toString();
String txtstatus = String.valueOf(status);
String confirm = txtConfirm.getText().toString();
String txtconfirm = String.valueOf(confirm);
Bundle bundle = new Bundle();
bundle.putString("status", txtstatus);
bundle.putString("confirm",txtconfirm);
a.putExtras(bundle);
startActivityForResult(a, 0);
Just put your 2nd string in with bundle.putString() making sure you use a unique key name for it.
The process of serializing/parceling custom objects, attaching to the bundle with keys and undoing all this at the other end gets tedious when you have a lot of data or/and when the data needs to serve different purposes/functions in the launched Activity etc.
You can check out this library(https://github.com/noxiouswinter/gnlib_android/wiki#gnlauncher) I wrote to try and solve this problem.
GNLauncher makes sending objects/data to an Activity from another Activity etc as easy as calling a function in the Activity with the required data as parameters. It introduces type safety and removes all the hassles of having to serialize, attaching to the intent using string keys and undoing the same at the other end.
You can also trigger different functionalities in the Activity directly by choosing which method to launch into with the data.
精彩评论