views:

178

answers:

2

Hi

I've got a widget on the Android market called DigiClock widget, and after the last update i've been having some extremely rare and random problems on rooted Motorola Droids ( there may be other handsets with the problem, but the only responses i've had are from rooted droid users ). The problem occurs when an activity is launched that runs an AsyncTask that retrieves all the installed applications from the device while showing a ProgressDialog ( Horizontal style ). The applicable java code file can be found here:

http://code.google.com/p/android-digiclockwidget/source/browse/trunk/src/com/davidgoemans/simpleClockWidget/LauncherChooser.java

If you wish to diff the changes made between a working and non-working version, that can be found here:

http://code.google.com/p/android-digiclockwidget/source/diff?spec=svn10&old=7&r=9&format=side&path=/trunk/src/com/davidgoemans/simpleClockWidget/LauncherChooser.java

What seems to happen on the droid is: * Progress box pops up * Progress box dismisses before it's finished running * Empty list shows up

It seems like the AsyncTask that fetches the applications is getting killed. Is this possible?

Thanks, David

EDIT:

Found the problem, turns out that in Android 2.0 ( NOT 2.1 or 1.6 )

List packages = getPackageManager().getInstalledPackages(PackageManager.GET_ACTIVITIES);

crashes in my situation, but

List packages = getPackageManager().getInstalledPackages(0);

doesn't.

+2  A: 

I am not certain whether it is the cause of the symptoms but I can see some problems with the code:

  • You must not manipulate UI objects like your ProgressDialog from any thread except for the main UI thread, because UI objects are not thread-safe. Instead of calling progressDialog.setProgress(), call AsyncTask.publishProgress() and then override AsyncTask.onProgressUpdate().

http://developer.android.com/resources/articles/painless-threading.html

  • Also, your code does not prevent both threads from accessing "menuEntries" at the same time. The simplest way to fix this part would be to move the call to setListAdapter() out of onCreate() and into onPostExecute().
Luke Dunstan
wow, thanks. i didn't realise that ProgressDialog was also affected. i'll try it out tonight and see if it works.
DavidG
thanks, but i've found the problem ( see above )
DavidG
A: 

Found the problem, turns out that in Android 2.0 ( NOT 2.1 or 1.6 )

List packages = getPackageManager().getInstalledPackages(PackageManager.GET_ACTIVITIES);

crashes in my situation, but

List packages = getPackageManager().getInstalledPackages(0);

doesn't. I found this by testing in the 2.0 emulator. This adds to the pain of having to test my app now on 1.5, 1.6, 2.0 and 2.1 instead of just the fringe cases :/

DavidG