我在 FragmentActitvity 中显示了谷歌地图,它实现并打开这个活动我从另一个活动(比如说活动 A)开始一个意图,点击一个按钮。
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext(), MapActivity.class);
startActivity(intent);
}
});
我的 MapActivity 是这样的:
public class MapActivity extends FragmentActivity implements GooglePlayServicesClient.ConnectionCallbacks,
GooglePlayServicesClient.OnConnectionFailedListener {
private GoogleMap googleMap;
private LocationClient locationClient;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map);
if (googleMap == null) {
googleMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
googleMap.setMyLocationEnabled(true);
// check if map is created successfully or not
if (googleMap == null) {
Toast.makeText(getApplicationContext(), "Sorry! unable to create maps", Toast.LENGTH_SHORT).show();
}
}
locationClient = new LocationClient(this, this, this);
locationClient.connect();
mLocationRequest = LocationRequest.create();
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
mLocationRequest.setInterval(5 * 1000);
mLocationRequest.setSmallestDisplacement(0.1f);
mLocationRequest.setFastestInterval(5 * 1000);
}
}
MapActivity 还有其他接口的实现方法。但是当我点击按钮打开 MapActivity 时,我得到了错误:
java.lang.IllegalArgumentException: Service Intent must be explicit: Intent { act=com.google.android.location.internal.GoogleLocationManagerService.START }
我在谷歌上搜索,发现我需要创建一个明确的意图。但我不确定在我的情况下如何做到这一点。