title: Cannot start activity from Service in Android 11 devices
body: <p>I got this issue when I tried to start an activity from a service in android 11 devices only:</p>
  <pre><code>    Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean com.android.server.wm.ActivityRecord.isVisible()' on a null object reference
          at android.os.Parcel.createExceptionOrNull(Parcel.java:2379)
          at android.os.Parcel.createException(Parcel.java:2357)
          at android.os.Parcel.readException(Parcel.java:2340)
          at android.os.Parcel.readException(Parcel.java:2282)
          at android.app.IActivityTaskManager$Stub$Proxy.startActivity(IActivityTaskManager.java:3696)
          at android.app.Instrumentation.execStartActivity(Instrumentation.java:1723)
          at android.app.ContextImpl.startActivity(ContextImpl.java:1023)
          at android.app.ContextImpl.startActivity(ContextImpl.java:994)
          at android.content.ContextWrapper.startActivity(ContextWrapper.java:403)
  </code></pre>
  <p>Even though I had the <code>System_alert_window</code> permission which was granted by me, it threw an error above. I checked <code>Settings.canDrawOverlays(context)</code> before start an activity:</p>
  <pre><code>if (Settings.canDrawOverlays(context)) {
       Intent intent1 = new Intent(context, MyActivity.class);                               
       intent1.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_FROM_BACKGROUND);
       context.startActivity(intent1);
  }
  </code></pre>
  <p>This is the docs: <a href="https://developer.android.com/guide/components/activities/background-starts#exceptions" rel="nofollow noreferrer">https://developer.android.com/guide/components/activities/background-starts#exceptions</a>.
  Does anyone have a solution for this?</p>