Reputation: 4981
In my app I need to send a
String[] titlephotos;
to another Activity. I think that with Bundle it is not possible. How can I do this? Can anyone help me?
Thanks in advance.
Upvotes: 0
Views: 498
Reputation: 8647
if you are using
public class SECOND_ACTIVITY extends LAST_ACTIVITY {...
you can use static String s;
if you are using
public class SECOND_ACTIVITY extends Activity{...
use this in fisrt activity:
Intent myIntent = new Intent(v.getContext(), SECOND_ACTIVITY.class);
myIntent.putExtra("STRING_NAME", VALUE_OF_STRING);
startActivityForResult(myIntent, 0);}
call string in SECOND_ACTIVITY:
Bundle extras = getIntent().getExtras();
STRING = extras.getString("STRING_NAME");
Upvotes: 1
Reputation: 2920
Sending arrays with Intent.putExtra
Use intent.putExtra(arrayvar);
in sending Activity
and
Bundle extras = getIntent().getExtras();
extras.getStringArray("numbers");
in the recipient activity.
Upvotes: 2
Reputation: 299
You can do several thins here, you can create a static field in the destination class and set the string array before launching the intent.
A nicer solution in my opinion is to create a singleton class to hold all variables you want to send between activitys. This is what i always did, if there is anyone with a nicer solution please tell.
Good luck!
Edit: sorry ofcourse you can just use the standard bundle option, i read too quick and thought you were talking about custom objects! my bad
Upvotes: 0