che*_*tan 12 arrays android bundle
我需要将一个String/integer值数组从一个Activity传递给另一个Activity.我该如何实现这一目标?
Nik*_*iki 29
在活动A:
String[] abc;
Bundle bundle =new Bundle();
bundle.putStringArray("some string",abc);
Run Code Online (Sandbox Code Playgroud)
在活动B中,您希望获得以下代码:
String abcd[]=bundle.getStringArray("some string");
Run Code Online (Sandbox Code Playgroud)
在某些情况下,"某些字符串"应该相同.
小智 5
在发送方,代码应为:
String[] myStrings=new String[2];
myStrings[0]="MONDAY";
myStrings[1]="TUESDAY";
Intent intent = new Intent(v.getContext(), Animation_program.class);
Bundle bundle = new Bundle();
intent.putExtra("strings", myStrings);
intent.putExtras(bundle);
startActivity(intent);
Run Code Online (Sandbox Code Playgroud)
在接收方,代码应为:
Intent i = getIntent();
Bundle extras=i.getExtras();
if(extras != null) //this line is necessary for getting any value
{
String[] fajr_Values = i.getStringArrayExtra("strings");
Toast.makeText(this, "value="+fajr_Values[0]+""+fajr_Values[1], Toast.LENGTH_SHORT).show();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
28196 次 |
| 最近记录: |