tags:

views:

10

answers:

1

Whenever I start the application it keeps force closing citing the log below. Is this a CPU overload issue or memory management issue? I really don't understand how to resolve this? Any help is much appreciated.

I am running Eclipse v 3.5.2 and Android SDK 0.98 and AVD is Froyo (2.2)

DDMS Log

10-10 23:53:53.379: ERROR/ActivityManager(60): ANR in Test.Tooyoou 10-10 23:53:53.379: ERROR/ActivityManager(60): Reason: Executing service Test.Tooyoou/.TooyoouWidget$UpdateService 10-10 23:53:53.379: ERROR/ActivityManager(60): Load: 1.17 / 0.68 / 0.26 10-10 23:53:53.379: ERROR/ActivityManager(60): CPU usage from 20436ms to 33ms ago: 10-10 23:53:53.379: ERROR/ActivityManager(60): adbd: 3% = 0% user + 3% kernel / faults: 10 minor 10-10 23:53:53.379: ERROR/ActivityManager(60): Test.Tooyoou: 2% = 2% user + 0% kernel / faults: 197 minor 4 major 10-10 23:53:53.379: ERROR/ActivityManager(60): system_server: 2% = 1% user + 0% kernel / faults: 134 minor 2 major 10-10 23:53:53.379: ERROR/ActivityManager(60): ndroid.settings: 1% = 1% user + 0% kernel / faults: 3016 minor 12 major 10-10 23:53:53.379: ERROR/ActivityManager(60): ndroid.launcher: 0% = 0% user + 0% kernel / faults: 32 minor 10-10 23:53:53.379: ERROR/ActivityManager(60): m.android.phone: 0% = 0% user + 0% kernel / faults: 174 minor 10-10 23:53:53.379: ERROR/ActivityManager(60): ronsoft.openwnn: 0% = 0% user + 0% kernel / faults: 99 minor 10-10 23:53:53.379: ERROR/ActivityManager(60): d.process.media: 0% = 0% user + 0% kernel / faults: 22 minor 10-10 23:53:53.379: ERROR/ActivityManager(60): netd: 0% = 0% user + 0% kernel / faults: 64 minor 1 major 10-10 23:53:53.379: ERROR/ActivityManager(60): com.svox.pico: 0% = 0% user + 0% kernel / faults: 26 minor 10-10 23:53:53.379: ERROR/ActivityManager(60): +sh: 0% = 0% user + 0% kernel 10-10 23:53:53.379: ERROR/ActivityManager(60): +logcat: 0% = 0% user + 0% kernel 10-10 23:53:53.379: ERROR/ActivityManager(60): TOTAL: 11% = 5% user + 4% kernel + 0% irq + 0% softirq

A: 

OK folks I think I solved the problem behind this very ugly error. There was some issue with the BroadcastReceiver TimeOut and the Update service for the widget taking too long. Here I how I solved it.

Instead of doing everything using the Service for the AppWidget, I spawned a thread to do all the critical update work.

public static class UpdateService extends Service {
        Thread widgetUpdateThread;
        @Override
        public void onStart(Intent intent, int startId) {

        widgetUpdateThread = new Thread(){
            public void run(){
                RemoteViews updateViews =   
                                       buildUpdate(getApplicationContext());
                            ComponentName thisWidget = new 
                              ComponentName(getApplicationContext(), 
                                                       TooyoouWidget.class);
                AppWidgetManager manager =  
                      AppWidgetManager.getInstance(getApplicationContext());
                      manager.updateAppWidget(thisWidget, updateViews);

            }
        };
        widgetUpdateThread.start();
    }

    @Override
    public void onDestroy(){
        widgetUpdateThread.interrupt();
        super.onDestroy();
    }

     public RemoteViews buildUpdate(Context context) {
     //your code to create the Remoteviews update

}

}

Once I used the Thread, everything works like a charm and that ugly error is gone. May be this will be helpful for some of you guys.

Aakash