我有三個活動:onMapReady並不總是叫
MainActivity:
public void start_main_map(View view) {
Intent intent = new Intent(this, com.example.MainMap.class);
startActivity(intent);
}
MainMap:
protected GoogleApiClient mGoogleApiClient;
@Override
protected void onCreate(Bundle savedInstanceState) {
Log.i(TAG, "onCreate");
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
@Override
protected void onStart() {
Log.i(TAG, "onStart");
mGoogleApiClient.connect();
super.onStart();
}
@Override
protected void onStop() {
Log.i(TAG, "onStop");
mGoogleApiClient.disconnect();
super.onStop();
}
@Override
protected void onPause() {
Log.i(TAG, "onPause");
super.onPause();
}
@Override
public void onResume() {
Log.i(TAG, "onResume");
super.onResume();
}
@Override
public void onMapReady(GoogleMap googleMap) {
Log.i(TAG, "onMapReady");
// do some serious work here
}
指南:
private void implement_back_button() {
final Intent intent = new Intent(this, com.example.MainMap.class);
back = (Button) findViewById(R.id.back_button);
back.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(intent);
}
});
}
每當我去從MainActivity
到MainMap
我得到:
I/MainMap: onCreate
I/MainMap: onStart
I/MainMap: onResume
I/MainMap: onMapReady
然而,每當我去從Guide
到MainMap
(使用的back_button
或按在我的手機返回鍵),我只得到:
I/MainMap: onCreate
I/MainMap: onStart
I/MainMap: onResume
沒有,onMapReady
- 所以「嚴肅的工作」從未解決。我無法理解這種行爲。如何確保在所有情況下調用onMapReady
?
http://stackoverflow.com/a/41365553/4432830希望這有助於 – Sammer
你的問題不明確。你的意思是如果你去主要活動,onMapReady調用地圖活動,但如果你從其他活動回到地圖活動,onMapReady不打電話? –
是的,這正是我的意思 –