Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

App starts searching for GPS right on app start, not when needed

  • I have an Android app that has Google Maps V2 as part of functionality.
  • I have

    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    

    in my manifest, and everything else needed for maps to work.

  • My app starts not on the screen with maps.

Now the question is why does my phone (Galaxy Nexus, just in case) starts showing GPS icon in status bar right when app starts, but not when I get to the screen with maps and start to work with it? I don't need to track my location and use battery power when I'm not on maps screen.

For example What's App messenger also uses GPS for its map but the icon is showed only when you open the map screen, not right on the first activity that is launched.

Googled for couple of hours but found nothing at all. Any help will be appreciated!

Edited:

MapActivity class

private LocationListener mLocationListener = new LocationListener() {
    @Override
    public void onLocationChanged(Location location) {
    }
    @Override
    public void onStatusChanged(String provider, int status, Bundle extras) {
    }
    @Override
    public void onProviderEnabled(String provider) {
    }
    @Override
    public void onProviderDisabled(String provider) {
    }
};

@Override
public void onCreate(Bundle savedState) {
    super.onCreate(savedState);
    setContentView(R.layout.map_activity);

    startGPS();
    initMap();
    mMapView = (MapView) findViewById(R.id.map_google_map);
    mMapView.onCreate(null);
    mGoogleMap = mMapView.getMap();
    if (mGoogleMap != null) {
        customizeGoogleMap();
        loadAndFillMap();
    }
}

private void startGPS() {
    mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, mLocationListener);
}

private void initMap() {
    try {
        MapsInitializer.initialize(this);
    } catch (GooglePlayServicesNotAvailableException e) {
        e.printStackTrace();
    }
}

private void customizeGoogleMap() {
    mGoogleMap.getUiSettings().setMyLocationButtonEnabled(true);
    mGoogleMap.setMyLocationEnabled(true);
}

private void loadAndFillMap() {
    new LoadAndFillMapTask().execute();
}

private class LoadAndFillMapTask extends AsyncTask<Void, Void, Void> {
    @Override
    protected Void doInBackground(Void... params) {
        String address = Session.appData().getSelectedAddress();
        mMapLocation = Api.getMapApi().getMapLocation(address);
        return null;
    }
    @Override
    protected void onPostExecute(Void aVoid) {
        fillMap();
    }
}

private void fillMap() {
    // filling Google Map with markers etc.
}

@Override
public void onDestroy() {
    super.onDestroy();
    if (mMapView != null) {
        mMapView.onDestroy();
    }
    mLocationManager.removeUpdates(mLocationListener);
}
like image 902
Makks129 Avatar asked Jun 04 '13 07:06

Makks129


1 Answers

After a while we found out that the problem was in Flurry SDK we were using in our project...

By default Flurry starts to report location right from app start. To turn it off we used:

FlurryAgent.setReportLocation(false);

... /_-

like image 72
Makks129 Avatar answered Oct 03 '22 04:10

Makks129