0

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.

Gabrielle
  • 4,933
  • 13
  • 62
  • 122

4 Answers4

2

Sending arrays with Intent.putExtra

Use intent.putExtra(arrayvar); in sending Activity

and

Bundle extras = getIntent().getExtras();
extras.getStringArray("numbers");

in the recipient activity.

Community
  • 1
  • 1
Jana
  • 2,890
  • 5
  • 35
  • 45
1

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");  
Uroš Podkrižnik
  • 8,607
  • 5
  • 21
  • 31
0

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!

Wiki Singleton

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

nldev
  • 299
  • 3
  • 15
0

Bundle does have a "putStringArray" method ...

user410932
  • 2,915
  • 4
  • 22
  • 23