Thread in android

Posted by ravi adhikari on Stack Overflow See other posts from Stack Overflow or by ravi adhikari
Published on 2011-01-07T15:36:14Z Indexed on 2011/01/07 15:54 UTC
Read the original article Hit count: 178

Filed under:

Hi experts,

I need some help as i am just calling a method in a thread. now what i want is wait for reply form getData() method only for 15 seconds. If it reply before 15 seconds it should be terminated otherwise after 15 seconds it should be terminated. The code is given below:

boolean networkStatus;

private Runnable runnable; 

private ProgressDialog m_ProgressDialog = null;

        private Runnable returnRes = new Runnable() {

        @Override

        public void run() {

         if(networkStatus){

          setData();

         m_ProgressDialog.dismiss();

        }

    };

private void callGetdata(){

 runnable = new Runnable() {

        @Override

        public void run() { 

      networkStatus = getData();

             runOnUiThread(returnRes); 

        }

    };

    Thread thread = new Thread(null, runnable, "MovetoBackground");

    thread.start();

    m_ProgressDialog = ProgressDialog.show(this, "", getString(R.string.loadMsg), true);

}

© Stack Overflow or respective owner

Related posts about multithreading