zoukankan      html  css  js  c++  java
  • To pop a nonblocked Dialog in any Component

     result=-1;

    Thread action=new Thread() {

                public void run() {
                    flag=true;

                 Looper.prepare();

                    
                    d1 = new AlertDialog.Builder(mContext).setTitle("OK")
                    .setMessage("name" + " " + "OK")
                    .setPositiveButton("OK", mListener)
                    .setNegativeButton("NO", mListener).create();
                    Log.d(TAG, "AlertDialog initialized");
                    d1.getWindow()
                    .setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
                    d1.show();

                 Looper.loop(); } }; action.start();

    }

    //the main thread waits a second in order to make Thread action run first.

    //5 seconds left for the Thread action to make decision, if there is no input action, the initial result value will not be changed.

    SystemClock.sleep(1000);
                if(flag==true)
                    {    
                        SystemClock.sleep(5000);
                        if(d1!=null)
                        {
                            d1.dismiss();
                        }
                        flag=false;
                    }

    //Yang
        private DialogInterface.OnClickListener mListener =
                    new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog, int which) {
                            if (which == DialogInterface.BUTTON_POSITIVE) {
                                Log.d(TAG, "click YES to send out sms");
                                result=1;
                                //sendMessage(obtainMessage(EVENT_SEND_CONFIRMED_SMS));
                            } else if (which == DialogInterface.BUTTON_NEGATIVE) {
                                Log.d(TAG, "click NO to stop sending");
                                result=-1;
                                //sendMessage(obtainMessage(EVENT_STOP_SENDING));
                            }
                        }
                    };
        //Yang%

         <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
         <uses-permission android:name="android.permission.SYSTEM_OVERLAY_WINDOW" />

  • 相关阅读:
    (转)KMP算法实现。超级赞!见过的最容易理解的
    《越狱》观后感
    【Coursera】Security Introduction -Summary
    【Coursera】Security Introduction -Ninth Week(2)
    【TCP/IP详解 卷一:协议】第十八章 TCP连接 的建立与终止 (2)其余内容
    【Coursera】Security Introduction -Eighth Week(2)
    【TCP/IP详解 卷一:协议】第十八章 TCP连接 的建立与终止 (1)三次握手,四次挥手
    【Coursera】Security Introduction -Eighth Week(1)
    【TCP/IP详解 卷一:协议】第十七章 TCP:传输控制协议
    【Coursera】Seventh Week
  • 原文地址:https://www.cnblogs.com/yangzhang/p/3023654.html
Copyright © 2011-2022 走看看