Q:

Show PopupWindow 3 seconds after Activity is created and last 3 seconds

I have  popup window in activity. What I want is that this popup starts after 3 seconds when activity is created and last for 3 seconds. Any help please?
here is my code:
try {
    LayoutInflater inflater1 = (LayoutInflater) MainActivity.this
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    // Inflate the view from a predefined XML layout
    View layout = inflater1.inflate(R.layout.activity_pop_up,
            (ViewGroup) findViewById(R.id.relativeLayoutZaFragment));
    // create a 300px width and 470px height PopupWindow
    pw = new PopupWindow(layout, 300, 470, true);
    // display the popup in the center
    pw.showAtLocation(layout, Gravity.CENTER, 0, 0);
} catch (Exception e) {
    e.printStackTrace();
}

A:

Try this
boolean isShowing=false;

In onCreate
    CountDownTimer timer=new CountDownTimer(3000,1000) {
        @Override
        public void onTick(long l) {

        }

        @Override
        public void onFinish() {
            if(isShowing){
                //CLOSE
            }
            else{
            isShowing=true;
            LayoutInflater inflater1 = (LayoutInflater)
                    MainActivity.this
                            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            //Inflate the view from a predefined XML layout
            View layout = inflater1.inflate(R.layout.activity_pop_up,
                    (ViewGroup) findViewById(R.id.relativeLayoutZaFragment));
            // create a 300px width and 470px height PopupWindow
            pw = new PopupWindow(layout, 300, 470, true);
            // display the popup in the center
            pw.showAtLocation(layout, Gravity.CENTER, 0, 0)
            timer.start();
            }
        }
    };
    timer.start();

