简体   繁体   English

无法在未调用Looper.prepare()Android的线程内创建处理程序。 循环计时器

[英]Can't create handler inside thread that has not called Looper.prepare() Android. Loop in a timer

I'm trying to receive message from my php server by creating a thread in a service but it doesnt work. 我试图通过在服务中创建线程来从我的php服务器接收消息,但是它不起作用。 can't go in the while loop and the error message as title shows. 无法进入while循环,错误消息如标题所示。 Please Help. 请帮忙。

            //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);

最好使用asynctask并在asynctask doinbackground()mtd中接收msg。由于网络服务调用可能会花费更多时间,因此您无法在Android中阻塞主线程超过5秒。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android上的Junit测试领域。 无法在未调用Looper.prepare()的线程内创建处理程序 - Junit Testing Realm on Android. Can't create handler inside thread that has not called Looper.prepare() Android线程错误-无法在未调用Looper.prepare()的线程内创建处理程序 - Android thread error - Can't create handler inside thread that has not called Looper.prepare() 无法在未调用Looper.prepare()Android的线程内创建处理程序 - Can't create handler inside thread that has not called Looper.prepare() Android java.lang.RuntimeException:无法在未在Android中调用Looper.prepare()的线程内创建处理程序 - java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare() in Android 警报对话框崩溃Android测试 - “无法在未调用Looper.prepare()的线程内创建处理程序” - Alert Dialog crashes Android test - “Can't create handler inside thread that has not called Looper.prepare()” 无法在未调用Looper.prepare()的线程内创建处理程序-Android Marmalade - Can't create handler inside thread that has not called Looper.prepare() - Android Marmalade Android Gingerbread:无法在未调用Looper.prepare()的线程内创建处理程序 - Android Gingerbread: Can't create handler inside thread that has not called Looper.prepare() Android Studio错误:无法在尚未调用Looper.prepare()的线程内创建处理程序 - Android Studio Error: Can't create handler inside thread that has not called Looper.prepare() 无法在未调用Looper.prepare()android服务的线程内创建处理程序 - Can't create handler inside thread that has not called Looper.prepare() android service Android空指针异常,并且无法在尚未调用Looper.prepare()的线程内创建处理程序 - Android nullpointer exception and Can't create handler inside thread that has not called Looper.prepare()
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM