AsyncTask return value

前端 未结 4 1600
死守一世寂寞
死守一世寂寞 2020-12-05 06:47

My android app connects to my website to retrieve and upload information so I use an AsyncTask thread.

In one instance, I need my thread to return a true or a false

4条回答
  •  情书的邮戳
    2020-12-05 07:24

    Handler is the best way to do this in onPostExcecute() method simply do

    @Override
        protected void onPostExecute(Boolean bool) {
            super.onPostExecute(bool);
               Message msg=new Message();
                msg.obj=bool;
                mHandler.sendMessage(msg);
            }
        }
    

    and your message handler will be

    mHandler = new Handler() { 
        @Override 
        public void handleMessage(Message msg) { 
            bool i=(String)msg.obj;
        }
     };
    

提交回复
热议问题