开发者

How to send a String[] to another Activity?

In my app I need to send a

String[] titlephotos; to another Activity. I think that with Bundle it i开发者_JS百科s not possible. How can I do this? Can anyone help me?

Thanks in advance.


Sending arrays with Intent.putExtra

Use intent.putExtra(arrayvar); in sending Activity

and

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

in the recipient activity.


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");  


Bundle does have a "putStringArray" method ...


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜