title: How to turn off the GPS when Activity in minimize in Android?
body: <pre><code>public boolean onKeyDown(int keyCode, KeyEvent event){
       if (keyCode == KeyEvent.KEYCODE_BACK &amp;&amp; event.getRepeatCount() == 0){
        Context context = getActivity();
           String provider = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
          if (provider.contains("gps")){  
          final Intent poke = new Intent();
          poke.setClassName("com.android.settings", "com.android.settings.widget.SettingsAppWidgetProvider");
          poke.addCategory(Intent.CATEGORY_ALTERNATIVE);
          poke.setData(Uri.parse("3")); 
          context.sendBroadcast(poke);
          }     
       }
      return super.onKeyDown(keyCode, event);
  }
  </code></pre>
  
  <p>i did some Code but it can not disable the GPS. if you have a code please share it, i want GPS turn off when app is minimize or Closed and when app is started it will Automatically turn on the GPS, I turned it on but cant Turn off..</p>