Java – the application starts searching for GPS when the application starts, not when needed
>I have an Android application that includes Google Maps V2 as part of the feature
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
In my list, and everything I need to work on the map. > My app doesn't display maps on the screen
The question now is why my phone (Galaxy nexus, just in case) starts to display the GPS icon in the status bar when the application starts, but it doesn't when I reach the screen with a map and start using it? When I'm not on the map screen, I don't need to track my location and use battery power
For example, what app messenger also uses GPS as its map, but displays the icon only when you open the map screen, not on the first activity launched
Google searched for hours, but found nothing Any help will be appreciated!
Edit:
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,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); }
Solution
After a while, we found that the problem was in the flurry SDK we used in the project
By default, Flurry starts to launch the report location from the application To turn it off, we use:
FlurryAgent.setReportLocation(false);
… / _-