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 ,
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"));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.