[英]how to transfer more then one string from one activity to another in android
i have to transfer more then one string from one activity to another activity in android , i already know how to transfer one string from one to another string in android but for more then one string i can not found ways my code is here , 我必须在android中将一个字符串从一个活动转移到另一个活动,我已经知道如何在android中将一个字符串从一个字符串转移到另一个字符串但是对于多个字符串我找不到我的代码在这里的方式,
if (long_insert_row_index>0){
//Spinner spDepCMPName = (Spinner) findViewById(R.id.spDepCMPName);
// String strCMP= spDepCMPName.getSelectedItem().toString();
//String strCMP=depositecmpname;
//startActivity(new Intent(DepositActivity.this, AuditPointDetailsActivity.class).putExtra("insert_row_index",""+long_insert_row_index).putExtra("segment_name", spinner_segment.getSelectedItem().toString()).putExtra("audit_type_name", spinner_audit_type.getSelectedItem().toString()).putExtra("audit_type_id", audit_type_id).putExtra("segment_id", segment_id));
///please see commented section at bottom
startActivity(new Intent(DepositActivity.this, DepositeNextActivity.class)
.putExtra("insert_row_index",""+long_insert_row_index)
.putExtra("CMPName", depositecmpname));
}else {
Toast.makeText(DepositActivity.this,"Error while inserting data.Please re-enter data.",Toast.LENGTH_LONG).show();
}
}
Now i want to send both string from one activity to another , i dont know how to do that one . 现在我想将一个字符串从一个活动发送到另一个活动,我不知道该怎么做。
you can use code in your first activity like :- 你可以在第一个活动中使用代码,如: -
ArrayList<String> arr = new ArrayList<String>();
arr.add(long_insert_row_index);
arr.add( depositecmpname);
Intent intent = new Intent(firstactivity.this,secondActivity.class);
intent.putExtra("array_list", arr);
startActivity(intent);
Now in another class you can use this code saying :- 现在在另一个类中,您可以使用此代码说: -
Bundle extras = getIntent().getExtras();
ArrayList<String> arr = (ArrayList<String>)extras.getStringArrayList("array_list");
Toast.makeText(getApplicationContext(),""+arr.size(),Toast.LENGTH_LONG).show();
hope it will help 希望它会有所帮助
Use for open activity: 用于开放活动:
Intent intent = new Intent(activity, Activity2.class);
intent.putExtra("String1", "Hello!");
intent.putExtra("String2", "Hello!2")
activity.startActivity(intent);
In open activity: 在公开活动中:
getIntent.getStringExtra("String1");
getIntent.getStringExtra("String2");
Or use 或者使用
intent.putExtra("StringByteArr", "str".toByteArray());
and: 和:
String.valueOf(getIntent.getByteArrayExtra("StringByteArr"));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.