我正在尝试在两个活动之间传递参数,它们是tabhost的标签。如何从活动(Active.java)向第二个活动(Active2.java)正确发送值?我做错了什么?
Active.java
public class Active extends Activity {
private Intent intent;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_active);
// intent = new Intent(this,Active2.class);
intent = getParent().getIntent();
}
public void Location(View view) {
final LocationManager LocMgr = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
final LocationListener LocList = new LocationListener() {
@Override
public void onLocationChanged(Location location) {
double latitude = location.getLatitude();
double longitude = location.getLongitude();
LatLng point = new LatLng(latitude, longitude);
intent.putExtra("point", point);
intent.putExtra("Active",1);
TabActivity ta = (TabActivity) Active.this.getParent();
ta.getTabHost().setCurrentTab(1);
}
};
}
Active2.java
public class Active2 extends Activit {
private GoogleMap googleMap;
private GoogleApiClient client;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_active2);
getFragmentManager().findFragmentById(R.id.map)).getMap();
client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
updateGoogleMap();
}
void updateGoogleMap ()
{
Bundle extras = getIntent().getExtras();
if(null !=extras) {
LatLng point = (LatLng) extras.get("point");
TextView text = (TextView) findViewById(R.id.GpsStat) ;
text.setText("bylem");
googleMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
googleMap.addMarker(new MarkerOptions().position(point).title("point"));
}
}
}
答案 0 :(得分:1)
首先,我想说你的代码中有很多错误。你应该在质量上做出更多改进。阅读更多。
现在回答你的问题。
所以就像这样
Active.java中的
list1 = {
Items: [
{
ID: 1,
Name: "Zurich"
},
{
ID: 2,
Name: "London"
}, {
ID: 3,
Name: "New York"
}
]
};
list2 = {
Items: [
{
ID: -1,
Name: "Dummy"
},
{
ID: 0,
Name: "Dummy2"
}
]
};
list1.push(list2);
Active2.java中的
Intent intent = new intent(Active.this,Active2.class);
intent.putExtra("point", point);
intent.putExtra("Active",1);
startActivity(intent);