Reputation: 3288
I am using Google Maps V2 in my app and when I change orientation to landscape (or basically change th eorientation), the onMapClick method does not respond and does nto respond even after the orientaiton changes again. I know I could avoid this weird bug by setting configChange:orientation|screenSize , but then layouts of my dialogues do not change their layout from layout-portrait to layout-landscape when orientaiton changes. This all is in one activity. Has anyone encountered this issue? What is wrong with the maps? I don´t understand where is the problem, why the listener should be unregistered. I register it in onCreateMethod: @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);
DisplayMetrics dm = getResources().getDisplayMetrics();
screenWidth = dm.widthPixels;
screenHeight = dm.heightPixels;
FontUtils.setCustomFont(this, (ViewGroup) getWindow().getDecorView());
RelativeLayout topBar = (RelativeLayout) findViewById(R.id.topBar);
LinearLayout placeTextLayout = (LinearLayout)topBar
.findViewById(R.id.placeTextLayout);
placeTextView = (TextView) placeTextLayout.findViewById(R.id.placeText);
sharedPrefs = getSharedPreferences
(SkyConstants.PREFS_NAME,Context.MODE_PRIVATE);
String place = sharedPrefs.getString
(SkyConstants.PREF_LOCATION_ID,SkyConstants.PREF_LOCATION_DEFAULT);
dateTextView = (TextView) topBar.findViewById(R.id.dateText);
daysTextView = (TextView) topBar.findViewById(R.id.timeText);
updateTopBar();
setUpMapIfNeeded();
}
private void setUpMapIfNeeded()
{
if (mMap == null)
{
mMap = ((SupportMapFragment)getSupportFragmentManager()
.findFragmentById(R.id.map)).getMap();
}
if (mMap != null)
{
mMap.getUiSettings().setZoomControlsEnabled(true);
mMap.getUiSettings().setZoomGesturesEnabled(true);
mMap.setMapType(GoogleMap.MAP_TYPE_TERRAIN);
mMap.setOnMapClickListener(new OnMapClickListener()
{
@Override
public void onMapClick(LatLng point)
{
//do something
}
});
}
}
Upvotes: 1
Views: 2780
Reputation: 3288
Setting map to null in onCreate() method helped as I needed to handle orientation changes by the system. so first I set mMap=null then I setup the map.
Upvotes: 0
Reputation: 2617
This is due to the creation of the view for the orientation, If you are in portrait mode, and you change to landscape, it creates again the view, and you need to set the onClickListener again.
The same happens if you start the activity in landscape mode, to portrait.
Upvotes: 1