Passing an arraylist of arraylists

后端 未结 3 1334
[愿得一人]
[愿得一人] 2021-01-28 22:37

I know it\'s a commonly asked question and I looked at the solutions online, but I am having a difficulty implementing this on my own.

I have a class which contains thr

3条回答
  •  春和景丽
    2021-01-28 23:09

    I think that you can use Gson too.

    In your build.gradle

    implementation 'com.google.code.gson:gson:2.8.4'
    

    In the first activity

    Gson gson = new Gson();
    String json = gson.toJson(yourObject);
    intent.putExtra("yourKey", json);
    

    In the second activity

    Gson gson = new Gson();
    YourObject yourObject = gson.fromJson(getIntent().getStringExtra("yourKey"), YourObject.class);
    

    Easy and fast.

提交回复
热议问题