在包中设置和获取多维数组列表

Set and Get multi dimensional arraylist to and from a bundle

我有一个多维数组列表,想将它传递给 activity。我该怎么做?

我下面的代码是我目前所拥有的...

在我的新 activity 中,我做了一些事情并弹出 arraylist,然后将其捆绑。然后我用...

杀死我的 activity 和 return 到以前的 activity
        final ArrayList<ArrayList<String>> inviteList = new ArrayList<ArrayList<String>>();
//populate the arraylist
        Intent i = new Intent();
        i.putExtra("players", inviteList);

我的activity(return来自上一个activity)

    protected void onActivityResult(int requestCode, int resultCode,Intent data) {
        if (requestCode == 0) {
            //if (resultCode == RESULT_OK) {
                // A contact was picked.  Here we will just display it
                // to the user.
                Intent i=getIntent();
                Bundle extras = i.getExtras();
                inviteList = (ArrayList<ArrayList<String>>) i.getSerializableExtra("players");
}

resultcode 为 0,requestcode 为 0(这告诉我什么?)。 这行不通 - 我在另一端得到了 null....

您正在尝试从 ActivityIntent 中读取您的值。您应该从方法的 data 参数中读取它:

inviteList = (ArrayList<ArrayList<String>>) data.getSerializableExtra("players");