title: Launch Activity from FCM
body: <p>In my application, i need to launch an activity and turn screen on, when high-priority FCM message is received. It's an alarm activity, which is very, very important for users. 
  On most Android devices, the code is working fine. However, on some Huawei or LG devices, the activity is not launched when the device is in Doze mode, or in the pocket (proximity sensor). The behaviour should be similar like Alarm clocks, calls etc. 
  Here is my code:</p>
  
  <p>FirebaseMessagingService: </p>
  
  <pre><code>@Override
  public void onMessageReceived(RemoteMessage remoteMessage) {
       Intent dialogIntent = new Intent(getBaseContext(), AlarmActivity.class);
       dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
       dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
       dialogIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
       dialogIntent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
       getApplication().startActivity(dialogIntent);
  }
  </code></pre>
  
  <p>Alarm Activity: </p>
  
  <pre><code>@Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  
      // set flags so an activity fire on the screen
      getWindow().addFlags(
              WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD |
                      WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON |
                      WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
                      WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
      );
  
      setContentView(R.layout.activity_alarm);
      .
      .
  }
  </code></pre>
  
  <p>I wanted to use <a href="https://developer.android.com/reference/android/os/PowerManager.html#SCREEN_BRIGHT_WAKE_LOCK" rel="nofollow noreferrer">SCREEN_BRIGHT_WAKE_LOCK</a> before I launch an activity, but it's deprecated. </p>