Push Alert technic

How to push an activity or alert to screen , even when device is locked similar to Viber incomming message?

1)Create an activity (theme dialog or translucent) 

2)Override onAttacheToWindow as below


    public void onAttachedToWindow() {

        Window window = getWindow();


                | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED

                | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON

                | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);


3)when receiving new incomming message start it!

 © Xosrov 2016