title: MarkerInfoWindowAdapter causes a crash when user back to app from menu screen
body: <p>I am a newbie on Android and working a project which is contain GoogleMap V2 and Markers.
  It shows some locations on google map with their details.If users tap any marker on the map, it shows MarkerInfoWindow with tapped marker details as usual.</p>
  
  <p>When I run the project first time everything is fine and working. When I pressed the Menu button(device menu button) in my app, android quits the my app and backs to Main Screen as usual.</p>
  
  <p>But, when I resume my application(tapping the application icon from menu screen) and tap any marker on the map <strong>my App crushes.</strong> and gives me an error.</p>
  
  <p>If I press the Back Button(device back button) until back to main screen quit the app and when I resume the application with icon as usual, everything is working no crash or any error.</p>
  
  <p>What is the problem on my application ? Why my application is crashing when the user quits my application with Menu button, and why not crushing when the user quits with back button ? </p>
  
  <p>I know my English is bad. But, I tried my best. 
  Thank you for understanding.</p>
  
  <p><strong>There is my error;</strong></p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>01-15 13:18:05.678    3090-3090/com.xxx.xxxapp W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0xa62e3288)
  01-15 13:18:05.678    3090-3090/com.xxx.xxxapp E/AndroidRuntime﹕ FATAL EXCEPTION: main
      java.lang.NullPointerException
              at com.xxx.xxxapp.MarkerInfoWindowAdapter.getInfoContents(MarkerInfoWindowAdapter.java:25)
              at com.google.android.gms.maps.GoogleMap$13.g(Unknown Source)
              at com.google.android.gms.maps.internal.d$a.onTransact(Unknown Source)
              at android.os.Binder.transact(Binder.java:326)
              at com.google.android.gms.maps.internal.p.b(SourceFile:112)
              at com.google.maps.api.android.lib6.c.h.a(Unknown Source)
              at com.google.maps.api.android.lib6.c.h.a(Unknown Source)
              at com.google.maps.api.android.lib6.gmm6.c.h.b(Unknown Source)
              at com.google.maps.api.android.lib6.gmm6.c.j.c(Unknown Source)
              at com.google.maps.api.android.lib6.c.al.c(Unknown Source)
              at com.google.maps.api.android.lib6.c.aj.g(Unknown Source)
              at com.google.maps.api.android.lib6.c.al.h(Unknown Source)
              at com.google.maps.api.android.lib6.gmm6.c.h.a(Unknown Source)
              at com.google.maps.api.android.lib6.gmm6.o.aw.a(Unknown Source)
              at com.google.maps.api.android.lib6.gmm6.o.bf.a(Unknown Source)
              at com.google.maps.api.android.lib6.gmm6.o.be.a(Unknown Source)
              at com.google.maps.api.android.lib6.gmm6.o.bu.d(Unknown Source)
              at com.google.maps.api.android.lib6.gmm6.o.ak.onSingleTapConfirmed(Unknown Source)
              at com.google.maps.api.android.lib6.gmm6.i.g.onSingleTapConfirmed(Unknown Source)
              at com.google.maps.api.android.lib6.gmm6.i.i.handleMessage(Unknown Source)
              at android.os.Handler.dispatchMessage(Handler.java:99)
              at android.os.Looper.loop(Looper.java:137)
              at android.app.ActivityThread.main(ActivityThread.java:4745)
              at java.lang.reflect.Method.invokeNative(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:511)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
              at dalvik.system.NativeStart.main(Native Method)</code></pre>
  </div>
  </div>
  </p>
  
  <p><strong>There is my MainActivity class;</strong></p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>import android.os.Bundle;
  import android.support.v4.app.FragmentManager;
  import android.support.v4.app.FragmentTransaction;
  import android.support.v4.view.ViewPager;
  import android.support.v7.app.ActionBar;
  import android.support.v7.app.ActionBarActivity;
  import android.view.Menu;
  import android.view.MenuItem;
  
  
  public class MainActivity extends ActionBarActivity implements ActionBar.TabListener {
  
      SectionsPagerAdapter mSectionsPagerAdapter;
      ViewPager mViewPager;
      FragmentManager manager;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          manager = getSupportFragmentManager();
  
          // Set up the action bar.
          final ActionBar actionBar = getSupportActionBar();
          actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
  
          // Create the adapter that will return a fragment for each of the three
          // primary sections of the activity.
          mSectionsPagerAdapter = new SectionsPagerAdapter(this, getSupportFragmentManager());
  
          // Set up the ViewPager with the sections adapter.
          mViewPager = (ViewPager) findViewById(R.id.pager);
          mViewPager.setAdapter(mSectionsPagerAdapter);
  
          // When swiping between different sections, select the corresponding
          // tab. We can also use ActionBar.Tab#select() to do this if we have
          // a reference to the Tab.
          mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
              @Override
              public void onPageSelected(int position) {
                  actionBar.setSelectedNavigationItem(position);
              }
          });
  
          // For each of the sections in the app, add a tab to the action bar.
          for (int i = 0; i &lt; mSectionsPagerAdapter.getCount(); i++) {
              // Create a tab with text corresponding to the page title defined by
              // the adapter. Also specify this Activity object, which implements
              // the TabListener interface, as the callback (listener) for when
              // this tab is selected.
              actionBar.addTab(
                      actionBar.newTab()
                              .setText(mSectionsPagerAdapter.getPageTitle(i))
                              .setTabListener(this));
          }
  
      }
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          // Inflate the menu; this adds items to the action bar if it is present.
          getMenuInflater().inflate(R.menu.menu_main, menu);
          return true;
      }
  
      @Override
      public boolean onOptionsItemSelected(MenuItem item) {
          // Handle action bar item clicks here. The action bar will
          // automatically handle clicks on the Home/Up button, so long
          // as you specify a parent activity in AndroidManifest.xml.
          int id = item.getItemId();
  
          //noinspection SimplifiableIfStatement
          if (id == R.id.action_settings) {
              return true;
          }
  
          return super.onOptionsItemSelected(item);
      }
  
      @Override
      public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
          // When the given tab is selected, switch to the corresponding page in
          // the ViewPager.
          mViewPager.setCurrentItem(tab.getPosition());
  
      }
  
      @Override
      public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
      }
  
      @Override
      public void onTabReselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
      }
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p><strong>There is my Custom Marker Info class;</strong></p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>package com.xxx.xxxapp;
  
  public class Markers {
  
      public String mAdi;
      public String mAdres;
      public String mTelefon;
      public String mFace;
      public String mWeb;
      public boolean mGeceAcik;
      public boolean mMember;
      public boolean mBarinak;
      public Double mLatitude;
      public Double mLongtitude;
  
  
      public Markers(String mAdi, String mAdres, String mTelefon, String mFace, String mWeb, boolean mBarinak, boolean mGeceAcik, boolean mMember, Double mLatitude, Double mLongtitude) {
          this.mAdi = mAdi;
          this.mAdres = mAdres;
          this.mTelefon = mTelefon;
          this.mFace = mFace;
          this.mWeb = mWeb;
          this.mGeceAcik = mGeceAcik;
          this.mMember = mMember;
          this.mLatitude = mLatitude;
          this.mLongtitude = mLongtitude;
          this.mBarinak = mBarinak;
      }
  
      public boolean ismBarinak() {
          return mBarinak;
      }
  
      public void setmBarinak(boolean mBarinak) {
          this.mBarinak = mBarinak;
      }
  
      public String getmAdi() {
          return mAdi;
      }
  
      public void setmAdi(String mAdi) {
          this.mAdi = mAdi;
      }
  
      public String getmAdres() {
          return mAdres;
      }
  
      public void setmAdres(String mAdres) {
          this.mAdres = mAdres;
      }
  
      public String getmTelefon() {
          return mTelefon;
      }
  
      public void setmTelefon(String mTelefon) {
          this.mTelefon = mTelefon;
      }
  
      public String getmFace() {
          return mFace;
      }
  
      public void setmFace(String mFace) {
          this.mFace = mFace;
      }
  
      public String getmWeb() {
          return mWeb;
      }
  
      public void setmWeb(String mWeb) {
          this.mWeb = mWeb;
      }
  
      public boolean ismGeceAcik() {
          return mGeceAcik;
      }
  
      public void setmGeceAcik(boolean mGeceAcik) {
          this.mGeceAcik = mGeceAcik;
      }
  
      public boolean ismMember() {
          return mMember;
      }
  
      public void setmMember(boolean mMember) {
          this.mMember = mMember;
      }
  
      public Double getmLatitude() {
          return mLatitude;
      }
  
      public void setmLatitude(Double mLatitude) {
          this.mLatitude = mLatitude;
      }
  
      public Double getmLongtitude() {
          return mLongtitude;
      }
  
      public void setmLongtitude(Double mLongtitude) {
          this.mLongtitude = mLongtitude;
      }
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p><strong>There is my MapFragment class;</strong></p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>package com.xxx.xxxapp;
  
  import android.app.Dialog;
  import android.content.Context;
  import android.content.Intent;
  import android.location.Location;
  import android.location.LocationManager;
  import android.os.Bundle;
  import android.support.v4.app.Fragment;
  import android.util.Log;
  import android.view.KeyEvent;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.Toast;
  
  import com.google.android.gms.common.ConnectionResult;
  import com.google.android.gms.common.GooglePlayServicesUtil;
  import com.google.android.gms.location.LocationListener;
  import com.google.android.gms.maps.CameraUpdateFactory;
  import com.google.android.gms.maps.GoogleMap;
  import com.google.android.gms.maps.SupportMapFragment;
  import com.google.android.gms.maps.model.BitmapDescriptorFactory;
  import com.google.android.gms.maps.model.LatLng;
  import com.google.android.gms.maps.model.Marker;
  import com.google.android.gms.maps.model.MarkerOptions;
  
  import java.util.ArrayList;
  import java.util.HashMap;
  import java.util.Map;
  
  public class HaritaFragment extends Fragment implements LocationListener {
  
      private static GoogleMap mGoogleMap;
      public static HashMap&lt;Marker, Markers&gt; mMarkersHashMap;
      private ArrayList&lt;Markers&gt; mMyMarkersArray = new ArrayList&lt;Markers&gt;();
      private Map&lt;Marker, Markers&gt; allMarkersMap = new HashMap&lt;Marker, Markers&gt;();
  
      private LatLng latLng;
      private Double lat;
      private Double lng;
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
  
          return inflater.inflate(R.layout.fragment_harita, container, false);
      }
  
      @Override
      public void onResume() {
          super.onResume();
  
          // Getting Google Play availability status
          int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getActivity().getBaseContext());
  
          if (status != ConnectionResult.SUCCESS) { // Google Play Services are not available
  
              int requestCode = 10;
              Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status, getActivity(), requestCode);
              dialog.show();
  
          } else { // Google Play Services are available
  
              setsVetMarkers();
              setUpMap();
              plotMarkers(mMyMarkersArray);
  
          }
      }
  
      private void setsVetMarkers(){
  
          // Initialize the HashMap for Markers and MyMarker object
          mMarkersHashMap = new HashMap&lt;Marker, Markers&gt;();
  
          //public Markers(String mAdi, String mAdres, String mTelefon, String mFace, String mWeb, boolean mBarinak, boolean mGeceAcik, boolean mMember, Double mLatitude, Double mLongtitude)
  
          mMyMarkersArray.add(new Markers(
                  "PetVetam",
                  "Emirhan cad.",
                  "0532-555-5555",
                  "https://www.facebook.com",
                  "http://www.xxxx.com",
                  false,
                  true,
                  true,
                  Double.parseDouble("41.05484176"),
                  Double.parseDouble("29.00497913")));
  
          mMyMarkersArray.add(new Markers("marina", "Muallim Naci Cad. N:49 D:3 Ortaköy Mah.", "0212-265-0000","YOK" ,
                  "YOK", true, false, true, Double.parseDouble("41.048846"), Double.parseDouble("29.027924")));
  
          mMyMarkersArray.add(new Markers("Animate Vetamats", "Duygu Sk No:2 Levent", "0212-000000","https://www.facebook.com/pages/Animate-Veteriner/562263330470083" ,
                  "http://www.animate.com.tr", false, false, false, Double.parseDouble("41.094460"), Double.parseDouble("28.998754")));
  
  
      }
  
  
      private void plotMarkers(ArrayList&lt;Markers&gt; markers)
      {
          if(markers.size() &gt; 0)
          {
              for (Markers myMarker : markers)
              {
  
                  // Create user marker with custom icon and other options
                  MarkerOptions markerOption = new MarkerOptions().position(new LatLng(myMarker.getmLatitude(), myMarker.getmLongtitude()));
  
                  if (myMarker.ismGeceAcik()){
  
                      markerOption.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN));
              }
                  else if (myMarker.ismBarinak()){
  
                      markerOption.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_VIOLET));
                  }
  
                  Marker currentMarker = mGoogleMap.addMarker(markerOption);
                  mMarkersHashMap.put(currentMarker, myMarker);
                  allMarkersMap.put(currentMarker, myMarker);
  
                  mGoogleMap.setInfoWindowAdapter(new MarkerInfoWindowAdapter());
  
  
  
  
  
              }
          }
      }
  
      private void  setUpMap(){
  
          mGoogleMap = ((SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map)).getMap();
          mGoogleMap.setMyLocationEnabled(true);
  
          // Get the location manager
          LocationManager locationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);
          // Define the criteria how to select the location provider -&gt; use
          // default
  
          //Criteria criteria = new Criteria();
          //String provider = locationManager.getBestProvider(criteria, false);
  
          Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
  
          // Initialize the location fields
  
          //Location eğer varsa mapi usercurrent location ile yaratıyor.
          if (location != null) {
  
              onLocationChanged(location);
              latLng = new LatLng(lat, lng);
              mGoogleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 15));
  
              //Location yoksa default value ve zoom value ile yaratıyor.
          }else{
  
              latLng = new LatLng(41.048846, 29.027924);
              Toast.makeText(getActivity(),getActivity().getString(R.string.location_error_message),Toast.LENGTH_LONG).show();
              mGoogleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 10));
          }
  
          //OnClick Info Window Listener...
          mGoogleMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
              @Override
              public void onInfoWindowClick(Marker marker) {
  
                  //Set your InfoWindow Click Events...
  
                  Markers selectedMarkerInfo = allMarkersMap.get(marker);
  
                  Intent intent = new Intent(getActivity(),DetailActivity.class);
  
                  intent.putExtra("adi",selectedMarkerInfo.getmAdi());
                  intent.putExtra("adres",selectedMarkerInfo.getmAdres());
                  intent.putExtra("web",selectedMarkerInfo.getmWeb());
                  intent.putExtra("face",selectedMarkerInfo.getmFace());
                  intent.putExtra("tel",selectedMarkerInfo.getmTelefon());
                  intent.putExtra("lat",selectedMarkerInfo.getmLatitude().toString());
                  intent.putExtra("lng",selectedMarkerInfo.getmLongtitude().toString());
                  intent.putExtra("gece",selectedMarkerInfo.ismGeceAcik());
                  intent.putExtra("member",selectedMarkerInfo.ismMember());
                  intent.putExtra("barinak",selectedMarkerInfo.ismBarinak());
  
                  startActivity(intent);
  
              }
          });
  
      }
  
      @Override
      public void onLocationChanged(Location location) {
  
              lat = (Double) (location.getLatitude());
              lng = (Double) (location.getLongitude());
      }
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p><strong>And There is MarkerInfoWindowAdapter class ;</strong></p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>package com.xxx.xxxapp;
  
  import android.view.View;
  
  import com.google.android.gms.maps.GoogleMap;
  import com.google.android.gms.maps.model.Marker;
  
  public class MarkerInfoWindowAdapter implements GoogleMap.InfoWindowAdapter
  {
      public MarkerInfoWindowAdapter()
      {
  
      }
  
      @Override
      public View getInfoWindow(Marker marker)
      {
          return null;
      }
  
      @Override
      public View getInfoContents(Marker marker)
      {
          Markers myMarker = HaritaFragment.mMarkersHashMap.get(marker);
          marker.setTitle(myMarker.getmAdi());
          marker.setSnippet(myMarker.getmAdres());
  
          return null;
      }
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>There is the AndroidManifest.xml ;</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.xxx.xxxapp" &gt;
  
      &lt;uses-permission android:name="android.permission.INTERNET" /&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /&gt;
      &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt;
      &lt;!--
           The following two permissions are not required to use
           Google Maps Android API v2, but are recommended.
      --&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /&gt;
      &lt;uses-permission android:name="android.permission.CALL_PHONE" /&gt;
      &lt;uses-permission android:name="android.permission.INTERNET" /&gt;
  
      &lt;uses-feature
          android:glEsVersion="0x00020000"
          android:required="true" /&gt;
  
      &lt;application
          android:allowBackup="true"
          android:icon="@drawable/ic_launcher"
          android:label="@string/app_name"
          android:theme="@style/AppTheme" &gt;
          &lt;meta-data
              android:name="com.google.android.gms.version"
              android:value="@integer/google_play_services_version" /&gt;
          &lt;meta-data
              android:name="com.google.android.maps.v2.API_KEY"
              android:value="@string/API_KEY" /&gt;
  
          &lt;activity
              android:name=".MainActivity"
              android:label="@string/app_name"
              android:screenOrientation="portrait" &gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
  
          &lt;activity
              android:name=".DetailActivity"
              android:label="@string/title_activity_detail"
              android:screenOrientation="portrait" &gt;
              android:parentActivityName=".MainActivity" &gt;
              &lt;meta-data
                  android:name="android.support.PARENT_ACTIVITY"
                  android:value="com.xxx.xxxapp.MainActivity" /&gt;
          &lt;/activity&gt;
          &lt;activity
              android:name=".ListVets"
              android:label="@string/title_activity_list_vets"
              android:parentActivityName=".MainActivity" &gt;
              &lt;meta-data
                  android:name="android.support.PARENT_ACTIVITY"
                  android:value="com.xxx.xxxapp.MainActivity" /&gt;
          &lt;/activity&gt;
  
  
      &lt;/application&gt;
  
  &lt;/manifest&gt;</code></pre>
  </div>
  </div>
  </p>