title: Floating widget restarting issue in Android pre - API 26 (> API 26)
body: <p>I have an application where I have a floating widget running as Service.</p>
  <p>But whenever I close the app, the widget (service) is restarted. this doesn't happen on API 26+</p>
  <p><strong>manifest.xml</strong></p>
  <pre><code> &lt;service
          android:name=&quot;.widget&quot;
          android:enabled=&quot;true&quot;
          android:exported=&quot;false&quot;/&gt;
  </code></pre>
  <p><strong>widget.java</strong></p>
  <pre><code>public class widget extends Service {
  
  private WindowManager mWindowManager;
  private View view;
  static boolean expanded = false;
  
  
  
  @Nullable
  @Override
  public IBinder onBind(Intent intent) {
      return null;
  }
  
  
  @Override
  public int onStartCommand(Intent intent, int flags, int startId) {
  
      return START_STICKY;
  }
  
  @Override
  public void onCreate() {
      super.onCreate();
      setTheme(R.style.AppTheme);
      view = LayoutInflater.from(this).inflate(R.layout.widget, null);
  
  
      int layoutFlag = android.os.Build.VERSION.SDK_INT &gt;= android.os.Build.VERSION_CODES.O ? TYPE_APPLICATION_OVERLAY : TYPE_PHONE;
      final WindowManager.LayoutParams params = new WindowManager.LayoutParams(
              WindowManager.LayoutParams.WRAP_CONTENT,
              WindowManager.LayoutParams.WRAP_CONTENT,
              layoutFlag,
              WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
              PixelFormat.TRANSLUCENT);
  
      params.gravity = Gravity.CENTER | Gravity.START;
  
  
      mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
      mWindowManager.addView(view, params);
  
  
  }
  
  @Override
  public void onDestroy() {
      super.onDestroy();
      if (view != null) {
          mWindowManager.removeView(view);
      }
  }
  </code></pre>
  <p><strong>MainActivity.java</strong></p>
  <pre><code>intent = new Intent(MainActivity.this, widget.class);
  startService(intent);
  </code></pre>
  <p><strong>Note: Permission is granted</strong></p>
  <p>So this works fine on any device above or equal to API 26
  and it still works on devices below api 26 but it has that restarting issue, any idea what might be causing that and how can I deal with it?</p>
  <p>also notice the only thing that differs the 2 versions in code is this part</p>
  <pre><code>int layoutFlag = android.os.Build.VERSION.SDK_INT &gt;= android.os.Build.VERSION_CODES.O ? TYPE_APPLICATION_OVERLAY : TYPE_PHONE;
  </code></pre>