0

我试图通过在服务中创建一个线程来从我的 php 服务器接收消息,但它不起作用。无法进入 while 循环和标题显示的错误消息。请帮忙。

            //Set the schedule function and rate
            Timer t = new Timer();
            t.scheduleAtFixedRate(new TimerTask() {

                    @Override
                    public void run() {
                        runOnUiThread(new Runnable() {

                            @Override
                            public void run() {


                        // TODO Auto-generated method stub



                            }

                        });
                    }

                    private void runOnUiThread(Runnable runnable) {
                        // TODO Auto-generated method stub
                        String flag = receivermessage();
                        while (flag.equals("N")){
                            notifyUser();
                        }
                        Log.d(TAG, "Download Successful");
                    }



            }, 0, 10000);
4

1 回答 1

0

最好使用 asynctask 并在 asynctask doinbackground() mtd 中接收 msg。因为 web 服务调用可能需要更多时间,你不能在 android 中阻塞主线程超过 5 秒。

于 2013-04-16T08:39:40.570 回答