ANR due to deadlock between app and widget?

99封情书 提交于 2020-01-07 04:36:27

问题


I have an android app that a) performs an updateData() function (querying content providers and HTTP requests from internet among other things) in a thread, and b) has a home screen widget that performs the same updateData() function every 30mins (not in a thread).

a) looks like this:

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

b) looks like this :

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

Now people are reporting ANRs where threads are stopped at same place in updateData(context), one thread for a) and one for b). Stack traces look like the following:

1st example:

"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=default handle=-1345017808 | schedstat=( 5672943129 29267974835 13299 ) at android.os.BinderProxy.transact(Native Method) at android.content.ContentProviderProxy.bulkQueryInternal(ContentProviderNative.java:370) at 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=default handle=2955408 | schedstat=( 53100602 8822875969 600 ) at android.os.BinderProxy.transact(Native Method) at android.content.ContentProviderProxy.bulkQueryInternal(ContentProviderNative.java:370) at android.content.ContentProviderProxy.query(ContentProviderNative.java:408) at android.content.ContentResolver.query(ContentResolver.java:245) ...

2nd example:

"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=default handle=-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=default handle=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=default handle=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)

Looks like some kind of task deadlock. Any ideas how to solve this anyone please?


回答1:


I believe the issue is the fact I am doing a long process in the onUpdate() function of the widgetProvider. I modified my code to spawn a thread to perform the intensive functionality, and so far, no more freezes have been reported from users.



来源:https://stackoverflow.com/questions/7017783/anr-due-to-deadlock-between-app-and-widget

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!