i am working on a chat application like whatsapp, i am working on popup notification on lock screen. i developed the code but the problem is -- i used two buttons on the dialog like whatsapp as close and view, but the onclick listener on buttons is not working , because of the dialog not having focus, whenever i click on dialog anywhere the backgroud of click screen performs click. i need this type of dialog and functionality like --

![like this dialog in whatsapp](https://i.stack.imgur.com/AGzKX.jpg)

but the dialog not getting focus or problem is something else, i cant get it clearly please help.

to achive this i am using the service like following - 

```
public class PopupService extends Service{

    @Override
    public IBinder onBind(Intent intent) {
        Utils.printLog("on bind");
        return null;
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {

        Utils.printLog("on start command");
        PowerManager pm = (PowerManager) getApplicationContext().getSystemService(Context.POWER_SERVICE);
        WakeLock mWakeLock = pm.newWakeLock((PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), "YourServie");
        mWakeLock.acquire();
        mWakeLock.release();

        ///////////////////////////////////

        final WindowManager mWindowManager = (WindowManager) getApplicationContext().getSystemService(WINDOW_SERVICE);
        LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
        final View mView = inflater.inflate(R.layout.dialog_popup_notification_received, null);

        Utils.printLog("view" + mView.isClickable());
        mView.setClickable(true);
        mView.setFocusable(true);
        mView.setFocusableInTouchMode(true);

        mView.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                Utils.printLog("view" + mView.isClickable());
            }
        });

        TextView tvMessage = (TextView) mView.findViewById(R.id.TextViewMessageInPopupMessageReceived);
        tvMessage.setText(intent.getStringExtra("msg"));
        ImageButton ibSend = (ImageButton) mView.findViewById(R.id.imageButtonSendInPopupMessageReceived);
        TextView tvClose = (TextView) mView.findViewById(R.id.TextViewCloseInPopupMessageReceived);
        TextView tvView = (TextView) mView.findViewById(R.id.textviewViewInPopupMessageReceived);

        ibSend.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View arg0) 
            {
                Utils.printLog("send");
            }
        });
        tvClose.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View arg0) 
            {
                Utils.printLog("close");
            }
        });
        tvView.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View arg0) 
            {
                Utils.printLog("view");
            }
        });

        WindowManager.LayoutParams mLayoutParams = new WindowManager.LayoutParams(
        ViewGroup.LayoutParams.WRAP_CONTENT,
        ViewGroup.LayoutParams.WRAP_CONTENT, 0, 0,
        WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
        WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
        /* | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON */,
        PixelFormat.RGBA_8888);

        mWindowManager.addView(mView, mLayoutParams);
        mWindowManager.updateViewLayout(mView, mLayoutParams);

        return super.onStartCommand(intent, flags, startId);
    }

}

```