How to send a LatLng instance to new intent

百般思念 提交于 2019-12-01 05:24:29

use the putParcelable method to attached LatLng Object to a Bundle:

Bundle args = new Bundle();
args.putParcelable("from_position", fromPosition);
args.putParcelable("to_position", toPosition);

Now attach it to your intent:

i.putExtra("bundle", args);

To get it in your new activity:

Bundle bundle = getIntent().getParcelableExtra("bundle");
LatLng fromPosition = bundle.getParcelable("from_position");
LatLng toPosition = bundle.getParcelable("to_position");

Much easier way, since LatLng is parcelable:

on caller side:

LatLng position = new LatLng(16.099108, -22.812924); // Boa Vista
intent.putExtra("Pos", position);

On receiver side

LatLng position = getIntent().getExtras().getParcelable("Pos");
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!