passing Entire ArrayList from one activity

2019-08-05 06:24发布

I want to pass a ArrayList from one activity to other. I have found this link for pass arraylist from one activity to other useful.

But when I am using

    ArrayList<String> hyperlinks = new ArrayList<String>();
                           ...

    Intent myIntent=new Intent(Player.this,VideoActivity.class);
                    Bundle mBundle = new Bundle();  
                    mBundle.putStringArrayListExtra("hyperlinks", hyperlinks);
                    //mBundle.putString("filePath", hyperlinks.get(0));  
                    myIntent.putExtras(mBundle); 
                    Player.this.startActivity(myIntent);

Then I am getting error at mBundle.putStringArrayListExtra , Saying that The method putStringArrayListExtra(String, ArrayList) is undefined for the type Bundle

Please guide me how to do this??

Thanks

3条回答
Deceive 欺骗
2楼-- · 2019-08-05 07:04

check into Application. You can extend your own application, and save the arraylist here

check out ==> Extending Application to share variables globally

查看更多
Summer. ? 凉城
3楼-- · 2019-08-05 07:04

Bundle Documentation clearly indicating that putStringArrayList(String, ArrayList) is method of Bundle class, but not putStringArrayListExtra()

http://developer.android.com/reference/android/os/Bundle.html#putStringArrayList(java.lang.String, java.util.ArrayList)

Also, please Check import declarations, and check if Proper Bundle class has been imported or not.

Package of Bundle class should be:

import android.os.Bundle;
查看更多
混吃等死
4楼-- · 2019-08-05 07:07

There's lots of ways to do it, but have you tried:

myIntent.putStringArrayListExtra(key, hyperlinks);

Also, the Bundle object has

 putStringArrayList
查看更多
登录 后发表回答