I've got multiple buttons, when each one is clicked they all launch the same activity. Depending on the button clicked the second activity will load a different String Array, how do I pass and catch a string array via an intent? Note the String Arrays are saved in an .xml file.
At the moment the second activity is just loading a specific array
res = getResources();
arraytoload = res.getStringArray(R.array.ninetyseven);
How would I get the button to send a message containing for example (R.array.twentyfive) and then have that load as arraytoload.
First activity
one.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent("com.example.test.MainActivity");
intent.putExtra("id", "ninetyseven");
startActivity(intent);
}
});
Second activity
private String[] arraytoload;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String idString = getIntent().getExtras().getString("id");
int id = getResources().getIdentifier(idString, "array", getPackageName());
arraytoload = res.getStringArray(id);
}