title: GPS location update stops updating when put app in background and turn off screen on huawei mya-L22
body: <p>I have an android application with a foreground service that listens to gps location updates, I am using LocationManager with gps provider only.</p>
  
  <p>I have this piece of code:</p>
  
  <pre><code>        Intent intent = new Intent(this, LocationUpdateReceiver.class);
  
          PendingIntent pi = PendingIntent.getBroadcast(this, 0, intent,
                  PendingIntent.FLAG_UPDATE_CURRENT);
  
          this.locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, this.INTERVAL, 0.0f, pi);
  </code></pre>
  
  <p>I'm getting location updates through receiver. It is working correctly when screen is on, but when I turn the device screen off, it stop getting location updates. It is working on my redmi 5 device, and working as expected. but my problem apprears on huawei.</p>
  
  <p>Note:
  this.INTERVAL = 10000;
  I'm using wakeLock to prevent the device from sleeping as follows:</p>
  
  <pre><code>    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
      PowerManager.WakeLock wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "TAG:");
      wakeLock.aquire();
  </code></pre>
  
  <p>Also my service in Manifist.xml like this</p>
  
  <pre><code>          &lt;service android:name="com.arttech.services.LocationService" android:enabled="true" /&gt;
  </code></pre>
  
  <p>And finally, I'm showing notification for my foreground service as follows:</p>
  
  <pre><code>    Notification.Builder ongoing = new Notification.Builder(getBaseContext()).setSmallIcon(R.drawable.logo).setContentTitle("Location Service").setOngoing(true);
      if (Build.VERSION.SDK_INT &gt;= 26) {
          ongoing.setChannelId("myChannelID");
  
      }
      notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
  
      notificationManager.notify(NOTIFICATIONID, ongoing.build());     
  </code></pre>
  
  <p>Anyone can help me with this issue? I'm struggling for more than one month and I'm getting nowhere.</p>
  
  <p>Thanks     </p>
  
  <p>Update:</p>
  
  <p>I also tried to add my app as protected app manually through battery settings, but I get the same behavior. I tested some app called relive, and it records the GPS locations perfectly. What am I doing wrong?</p>
  
  <p>UPDATE: 
  Here are my OnStartCommand code:</p>
  
  <pre><code>@Override
  public int onStartCommand(Intent intent, int flags, int startId) {
  
      Log.d("omar","Service Started");
      LocationObserver.getInstance().addObserver(this);
  
  
      int SDK_INT = android.os.Build.VERSION.SDK_INT;
      if (SDK_INT &gt; 8)
      {
          Log.d("omar_build",SDK_INT+"");
  
          StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
                  .permitAll().build();
          StrictMode.setThreadPolicy(policy);
  
  
      }
  
      CreateConnectionInstance(); // Connect to socket
  
      startTracking();
      isLocationServiceRunning = true;
  
      return START_STICKY;
  }
  </code></pre>