从活动中唤醒等待线程的触摸事件?

时间:2014-03-06 10:31:16

标签: android

我有这个线程为onTouchEvent()

private Runnable disconnectCallback = new Runnable() {
    @Override
    public void run() {
    // Perform any required operation on disconnect
        runOnUiThread(new Runnable() {

            @Override
            public void run() {
                // TODO Auto-generated method stub
                Toast.makeText(getBaseContext(),"Your session expired Please Login again",Toast.LENGTH_SHORT).show();
                try {
                    wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

                final Logout l=new Logout();
                l.setContext(Ac2.this);// passing context of Ac3.java to Logout.java
                l.execute(sessid,uname);
            }
        });
    }
};  

我想要的是当用户触摸移动屏幕时通知此等待线程..

2 个答案:

答案 0 :(得分:0)

private Runnable disconnectCallback = new Runnable() {
    @Override
    public void run() {
        // Perform any required operation on disconnect
        runOnUiThread(new Runnable() {

            @Override
            public void run() {
                // TODO Auto-generated method stub
                Toast.makeText(getBaseContext(),
                        "Your session expired Please Login again",
                        Toast.LENGTH_SHORT).show();
                try {
                    synchronized (disconnectCallback) {
                        disconnectCallback.wait();
                    }
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

                final Logout l = new Logout();
                l.setContext(Ac2.this);// passing context of Ac3.java to
                                        // Logout.java
                l.execute(sessid, uname);
            }
        });
    }
};

并在onTouch事件中调用:

    disconnectCallback.notifyAll();

答案 1 :(得分:0)

试试这个

private Runnable disconnectCallback = new Runnable() {
    @Override
    public void run() {
        // Perform any required operation on disconnect
        runOnUiThread(new Runnable() {

            @Override
            public void run() {
                // TODO Auto-generated method stub
                Toast.makeText(getBaseContext(),
                        "Your session expired Please Login again",
                        Toast.LENGTH_SHORT).show();

            }
        });
        try {
            synchronized(disconnectCallback){
            disconnectCallback.wait();
            final Logout l=new Logout();
            l.setContext(Ac2.this);// passing context of Ac3.java to Logout.java
            l.execute(sessid,uname);

            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }


    }
};

在onTouch内部

synchronized (disconnectCallback) {
        disconnectCallback.notify();
    }