views:

164

answers:

1

I have been battling an ANR happening in one of my services for a while now. It is very hard to reproduce and the UI seems to have full functionality right before it happens 100% of the time there is never any noticeable lag or freezing. My service has a TimerTask and a few AsyncTask's that it runs and that is it.

The stack traces I get when you report it with the Android Market in 2.2 are hard to read, there doesn't seem to be a reference to any of my code directly but only from classes in the SDK. Can anyone take a look at the stacktrace and see if you can tell what is going on.

The print out is so large I opted to post it to pastebin, I hope that isn't against the rules. http://pastebin.com/KHUD0UHW

Here is the Logcat log as well http://pastebin.com/V5xSey36

+1  A: 

It's possible that it's not your apps fault. An ANR shows up for whatever the 'current' app is. However if another app on the system was really taking out your CPU and forcing your app to starve, your app will get the ANR because it has the user's focus. If that is the situation, there is nothing you can do. Perhaps the best way to test for this is watch for or force the system to do a sync. Syncs are usually quite heavy on the phone and can cause bad lag on less powerful phones.

Another way to test if you have a slower phone is to install a big app from the market. Once it goes in to the 'Installing' phase after downloading, do something just a little bit intensive in your app. If the installing phase takes longer than 5 seconds or so, it has quite a decent chance to make your app get the ANR. This is because of bad IO speeds while installing the app. IO blocks other apps from getting CPU time. Android thinks that means that you are stealing it.

Moncader