ANR由于app和widget之间的死锁?

时间:2011-08-10 21:04:03

标签: android android-widget

我有一个Android应用程序,a)在一个线程中执行updateData()函数(从互联网查询内容提供者和HTTP请求),以及b)有一个执行相同updateData()函数的主屏幕小部件每30分钟(不在一个帖子中)。

a)看起来像这样:

public class MoodMain extends Activity{
    public void onCreate(...)
    {
        Thread t = new Thread()
        {
            public void run()
            {
                     updateData(this);
            }
        };
        t.start();
    }

b)看起来像这样:

public class MoodAppWidgetProvider extends AppWidgetProvider { 
    public void onUpdate(Context context, ...)
    { 
        updateData(context);
    } }

现在人们正在报告ANR,其中线程在updateData(上下文)中的相同位置停止,一个线程用于a),一个用于b)。堆栈跟踪如下所示:

第一个例子:

  

“main”prio = 5 tid = 1 NATIVE | group =“main”sCount = 1 dsCount = 0 s = N.   obj = 0x40025ad8 self = 0xcd80 | sysTid = 23053 nice = 0 sched = 0/0   cgrp =默认句柄= -1345017808 | schedstat =(5672943129 29267974835   13299)在android.os.BinderProxy.transact(Native Method)at   android.content.ContentProviderProxy.bulkQueryInternal(ContentProviderNative.java:370)   在   android.content.ContentProviderProxy.query(ContentProviderNative.java:408)   ...

     

“Thread-10”prio = 5 tid = 9 NATIVE | group =“main”sCount = 1 dsCount = 0   s = N obj = 0x4629ba88 self = 0x2d1750 | sysTid = 23062 nice = 0 sched = 0/0   cgrp =默认句柄= 2955408 | schedstat =(53100602 8822875969 600)   在android.os.BinderProxy.transact(Native Method)at   android.content.ContentProviderProxy.bulkQueryInternal(ContentProviderNative.java:370)   在   android.content.ContentProviderProxy.query(ContentProviderNative.java:408)   在android.content.ContentResolver.query(ContentResolver.java:245)......

第二个例子:

  

“main”prio = 5 tid = 1 NATIVE | group =“main”sCount = 1 dsCount = 0 s = N.   obj = 0x40020a30 self = 0xcd88 | sysTid = 19319 nice = 0 sched = 0/0   cgrp =默认句柄= -1345026000 at   java.net.InetAddress.getaddrinfo(Native Method)at   java.net.InetAddress.lookupHostByName(InetAddress.java:508)at   java.net.InetAddress.getAllByNameImpl(InetAddress.java:280)at   java.net.InetAddress.getByName(InetAddress.java:310)at   java.net.InetSocketAddress。(InetSocketAddress.java:110)...

     

“Thread-10”prio = 5 tid = 9 NATIVE | group =“main”sCount = 1 dsCount = 0   s = N obj = 0x458842e8 self = 0x245cc0 | sysTid = 20153 nice = 0 sched = 0/0   cgrp =默认句柄= 2388904 at   java.net.InetAddress.getaddrinfo(Native Method)at   java.net.InetAddress.lookupHostByName(InetAddress.java:508)...

     

“Thread-8”prio = 5 tid = 7 NATIVE | group =“main”sCount = 1 dsCount = 0 s = N.   obj = 0x45867030 self = 0x22c528 | sysTid = 20151 nice = 0 sched = 0/0   cgrp =默认句柄= 2277944 at   java.net.InetAddress.getaddrinfo(Native Method)at   java.net.InetAddress.lookupHostByName(InetAddress.java:508)... at   com.admob.android.ads.i.d(AdMobURLConnector.java:153)at   com.admob.android.ads.b.a(AdRequester.java:206)at   com.admob.android.ads.AdView $ b.run(AdView.java:655)

看起来像某种任务死锁。有什么想法可以解决这个问题吗?

1 个答案:

答案 0 :(得分:0)

我认为问题在于我在widgetProvider的onUpdate()函数中执行了一个很长的过程。我修改了我的代码以生成一个线程来执行密集功能,到目前为止,用户还没有报告冻结。