简体   繁体   English

如何在Android中从活动获取Fragment活动的数据?

[英]How can i take data for Fragment activity from an activity, in android?

I have an fragmentActivity to visualize a map, now i need to take the coordinates (latitude and longitude) from another activity. 我有一个fragmentActivity来可视化地图,现在我需要从另一个活动中获取坐标(纬度和经度)。 How can i do? 我能怎么做?

If another activity is starting your map fragmentActivity , then you can simply pass those coordinated inside Intent Bundle. 如果另一个活动正在启动您的地图fragmentActivity,那么您可以简单地传递Intent Bundle中协调的那些活动。 For example: 例如:

Intent intent;
intent.putExtra("KEY_LATITUDE", 51.1232112);
intent.putExtra("KEY_LONGITUDE", 51.1232112);

in your map fragmentActivity, you will read those values inside onCreate using getIntent and appropiate methods. 在地图fragmentActivity中,您将使用getIntent和适当的方法在onCreate内读取这些值。

If this is the other way around, and your map activity is showing some other activity to ask for coordinates, then use onActivityResult and startActivityForResult mechanism. 如果这是相反的情况,并且您的地图活动正在显示其他活动来询问坐标,请使用onActivityResult和startActivityForResult机制。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM