実装する FragmentActivity に Google マップが表示されています。このアクティビティを開くには、ボタンをクリックして別のアクティビティ (アクティビティ 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 }
Google で検索したところ、明示的な意図を作成する必要があることがわかりました。しかし、私の場合、それを行う方法がわかりません。