Android - OnMyLocationChangeListener not work when I close and open again the activity -
in application i'm using maps api v2. have activity contains map:
<linearlayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:gravity="center" android:orientation="vertical"> <fragment android:id="@+id/map" android:name="com.google.android.gms.maps.supportmapfragment" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="center" /> </linearlayout>
when activity starts, shows location on map , updated using onmylocationchangelistener. works perfectly, have big problem:
when open activity works great, can see icon of location in notification bar
if push home button (the square button) of device, leave app, not close it. when reopen application, continues showing , updating location on map correct, comes problem.
when push device´s button, leave app, when open again, location no longer active (the location icon not shown in notification bar) , map not updated
i have tried many ways it, read forums , tutorials, without success. not know problem.
i appreciate help, confused.
thank much.
this code of activity:
public class home extends actionbaractivity {
public static googlemap mmap; //... private void setupmapifneeded() { if (mmap == null) { mmap = ((supportmapfragment) getsupportfragmentmanager().findfragmentbyid(r.id.map)).getmap(); if (mmap != null) { setupmap(); } } } private void setupmap() { mmap.setmylocationenabled(true); googlemap.onmylocationchangelistener mylocationchangelistener = new googlemap.onmylocationchangelistener() { @override public void onmylocationchange(location location) { latlng loc = new latlng(location.getlatitude(), location.getlongitude()); if (ll_ubicacion_mapa.getvisibility() == view.visible) { ll_ubicacion_mapa.setvisibility(view.gone); } else { } mmap.movecamera(cameraupdatefactory.newlatlngzoom(loc, 16.0f)); try { indicadordeposicion.remove(); } catch (exception e) { } indicadordeposicion = mmap.addmarker(new markeroptions() .flat(true) .title(getresources().getstring(r.string.txestasaqui)) .icon(bitmapdescriptorfactory.fromresource(r.mipmap.ic_launcher)) .anchor(0.5f, 0.5f) .position(new latlng(location.getlatitude(), location.getlongitude()))); } }; mmap.setonmylocationchangelistener(mylocationchangelistener); } @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.home); setupmapifneeded(); //... } @override protected void onresume() { super.onresume(); setupmapifneeded(); } protected void onpause() { super.onpause(); } }
Comments
Post a Comment