当前位置: 动力学知识库 > 问答 > 编程问答 >

android - How to pass an arrylist of LatLng from one activity to another

问题描述:

I want to pass an ArrayList of LatLng variables from one Activity to another through button click.

The one available for String is not working Please help me out....

网友答案:

Pass it as an ArrayList of Parcelable objects.

// Put the coordinates
ArrayList<LatLng> coordinates = new ArrayList<>();
Bundle bundle = new Bundle();
bundle.putParcelableArrayList("coordinates", coordinates);

// Get the coordinates
coordinates = bundle.getParcelableArrayList("coordinates");

To pass the bundle you need to the intent object you use to invoke the other activity:

Intent intent = new Intent(FirstActivity.this, SecondActivity.class);
intent.putExtras(bundle);
startActivity(intent);

Then in the SecondActivity's onCreate you fetch the bundle:

ArrayList<LatLng> coordinates = getIntent().getParcelableArrayListExtra("coordinates");
网友答案:

I think you should parceble class or getParceble()

check following link:link 1

link 2

分享给朋友:
您可能感兴趣的文章:
随机阅读: