listview item做倒计时thread线程导致anr 1C

int result = 0;<br>
    boolean flg = true;<br>
    public Thread thread;<br>
    public void start() {<br>
        if (thread == null){<br>
            thread = new Thread() {<br>
                public void run() {<br>
                    while (flg) {<br>
                        try {<br>
                            if (arrayList1 == null || result == arrayList1.size()) {<br>
                                break;<br>
                            }<br>
                            sleep(1);<br>
                            for (PurchaseDateil person : arrayList1) {<br>
                                if (Integer.parseInt(person.getPublicDate())>0) {<br>
                                    if ("1".equals(person.getPublicDate())) {<br>
                                        person.setPublicDate("0");<br>
                                        result++;<br>
                                        Intent intent = new Intent("com.example.cloudAndPurchasing.zhpt");<br>
                                        localBroadcastManager.sendBroadcast(intent);<br>
                                        flg = false;<br>
                                        break;<br>
                                    } else {<br>
                                        person.setPublicDate((Integer.parseInt(person.getPublicDate()) - 1) + "");<br>
                                    }<br>
                                }<br>
                            }<br>
                        } catch (InterruptedException e) {<br>
                            e.printStackTrace();<br>
                        }catch (ConcurrentModificationException e){<br>
                            e.printStackTrace();<br>
                        }catch (Exception e){<br>
                            LogUtil.e("AdapterNewPublish start error:",e.toString());<br>
                        }<br>
                    }<br>
                }<br>
            };<br>
        }<br>
        thread.start();<br>
//        MyThreadPoolManager.getInstance().execute(thread);<br>
    }<br>
        sleep(1);这行报错<br>
        图片说明

1个回答

线程已等待,超过5S即报ANR
通常情况下,你是线程倒计时,刷新到UI线程上,但子线程明明被等待了,可能由于内存吃紧的原因,你最好监听下exception,然后notify一下

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问