将可包裹的 ArrayList 从一个活动检索到另一个活动



我从一个活动检索 ArrayList 到另一个活动时遇到问题。"我的视频"类实现了"包裹"。

imageView.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        Bundle b = mVideos.get(numero).getAsBundle();
        Bundle a = new Bundle();
        // putting the parcelable mVideos, which is an array, into the bundle.
        a.putParcelableArrayList("videos", mVideos);
        final Intent i = new Intent("com.video.tv.description");
        i.putExtra("com.video.tv.description", b);
        i.putExtra("com.video.tv.Videos", a); // I added it to intent
        dAct.startActivity(i);
    }
});

如何在第二个活动上检索整个数组?

Bundle a = i.getBundleExtra("com.video.tv.Videos")?? 

正在尝试像以前一样获取整个阵列,就像我最初的活动一样。

d你的代码很奇怪,看起来你有很多不必要的捆绑包和漂浮的东西 在构建捆绑包时尝试以下操作:

imageView.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        // What is the purpose of this line?
        Bundle b = mVideos.get(numero).getAsBundle();
        Bundle a = new Bundle();
        a.putParcelableArrayList("videos", mVideos);
        // Replace YourNewActivity with the name of the Activity you want to start.
        Intent i = new Intent(dAct, YourNewActivity.class);
        i.putExtra("description", b);
        i.putExtra("videos", a); // I added it to intent
        dAct.startActivity(i);
    }
});

然后,在接收活动中,执行以下操作以获取列表:

Bundle i = getIntent().getExtras();
Bundle a = i.getBundleExtra("com.video.tv.Videos");
ArrayList<Video> videos = a.getParcelableArrayList("videos");

最新更新