【问题标题】:How to send and receive an ArrayList from one activity to another activity in Android? [duplicate]如何在Android中从一个活动发送和接收ArrayList到另一个活动? [复制]
【发布时间】:2014-02-20 18:36:21
【问题描述】:
        Bundle bundle = new Bundle();

        bundle.putParcelableArrayList("countiesof",
                (ArrayList<? extends Parcelable>) jsonDataList);
        Intent intent = new Intent(SplashActivity.this, HomeActivty.class);

        intent.putExtra("mycountries", jsonDataList);

        startActivity(intent);

现在,我想将 arraylist 从一个活动传递到另一个活动。

【问题讨论】:

  • 您在 jsonDataList 中存储了什么样的对象?它们可以打包吗?
  • 您的arraylist 是什么以及如何设计的?请显示您要传递的数组列表?
  • 带哈希映射的数组列表

标签: android


【解决方案1】:
  Intent intent = new Intent(SplashActivity.this, HomeActivty.class);

   putStringArrayListExtra(String name, ArrayList<String> value)

    startActivity(intent);

【讨论】:

  • jsonDataList.toString()?如果jsonDataList 是一个对象列表,这是一个好方法吗?
  • 你可以轻松使用它。
  • 这是一种非常糟糕的方法,您必须使用ParcelableSerializable 发送一个列表(我更喜欢Parcelable,因为它更快)
  • 我在哪里使用这个?你能给我看看吗?
【解决方案2】:

您可以像这样将 ArrayList 声明为静态的,

public static ArrayList<String> array = new ArrayList<String>();

通过这样做,您可以从任何地方访问您的 ArrayList

activity_name.array;

其中 activity_name 是您在其中声明静态 ArrayList 的活动或类

【讨论】:

    【解决方案3】:

    我已经要求将数据从一项活动传递给另一项活动。请阅读此主题。

    How to pass bean class one activity to another activity on android

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-07-20
      • 2014-05-03
      • 1970-01-01
      • 1970-01-01
      • 2014-09-06
      • 2016-11-04
      • 2012-07-20
      相关资源
      最近更新 更多