I made appwidget which updates UI layout through "Service".

In the emulater, it worked very well.
but,
in real phone, after the first install, worked normally.
but at the second re-install, not worked! "unexpectedly ..." and did't
start "Service".
what's wrong?

here are sources and logs.

widget class.
-----------------
public class MySimpleWidget extends AppWidgetProvider {
        static final String TAG = "xxx";
        static final String TAG1 = "xxx1";
        private static AppWidgetManager appWidgetManager;
        Intent intent;
        protected static PendingIntent pendingIntent;
        protected static AlarmManager alarmManager;
    public void onReceive(Context context, Intent intent) {
        // Protect against rogue update broadcasts (not really a
security issue,
        // just filter bad broacasts out so subclasses are less likely
to
        // crash).
        Log.d(TAG1, "onReceive ");
        String action = intent.getAction();
        if (action.equals("CLICK_RELOAD")) {
            Log.d(TAG, "ACTION_CLICK_RELOAD");
            Toast.makeText(context, "Data Collecting",
Toast.LENGTH_SHORT).show();
            xmlViewParser(context);
        } else if
(AppWidgetManager.ACTION_APPWIDGET_UPDATE.equals(action)) {
                Log.d(TAG, "ACTION_APPWIDGET_UPDATE");
                Toast.makeText(context, "최초자동업데이트중...",
Toast.LENGTH_SHORT).show();
            Bundle extras = intent.getExtras();
            if (extras != null) {
                int[] appWidgetIds = extras
                        .getIntArray(AppWidgetManager.EXTRA_APPWIDGET_IDS);
                if (appWidgetIds != null && appWidgetIds.length > 0) {
                    this.onUpdate(context, AppWidgetManager
                            .getInstance(context), appWidgetIds);
                }
            }
        } else if
(AppWidgetManager.ACTION_APPWIDGET_DELETED.equals(action)) {
            Log.d(TAG, "ACTION_APPWIDGET_DELETED");

            final int appWidgetId = intent.getExtras().getInt(
                    AppWidgetManager.EXTRA_APPWIDGET_ID,
                    AppWidgetManager.INVALID_APPWIDGET_ID);
            if (appWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID)
{
                this.onDeleted(context, new int[] { appWidgetId });
            }
            /*
             * Bundle extras = intent.getExtras(); if (extras != null
&&
             *
extras.containsKey(AppWidgetManager.EXTRA_APPWIDGET_ID)) { final
             * int appWidgetId = extras
             * .getInt(AppWidgetManager.EXTRA_APPWIDGET_ID);
             * this.onDeleted(context, new int[] { appWidgetId }); }
             */
        } else if
(AppWidgetManager.ACTION_APPWIDGET_ENABLED.equals(action)) {
            Log.d(TAG, "ACTION_APPWIDGET_ENABLED");

            this.onEnabled(context);
        } else if
(AppWidgetManager.ACTION_APPWIDGET_DISABLED.equals(action)) {
            Log.d(TAG, "ACTION_APPWIDGET_DISABLED");

            this.onDisabled(context);
        } else {
            super.onReceive(context, intent);
        }
    }

        @Override
        public void onUpdate(Context context, AppWidgetManager
appWidgetManager, int[] appWidgetIds){

        super.onUpdate(context, appWidgetManager, appWidgetIds);

        Log.d(TAG1, "onUpdate");
        if (appWidgetIds == null) {
            appWidgetIds = appWidgetManager.getAppWidgetIds(new
ComponentName(
                    context, MySimpleWidget.class));
        }

        if (appWidgetIds == null) {
                Log.d(TAG, "onUpdate appwidgetIds is null");
            return;
        }

        final int N = appWidgetIds.length;

        for (int i=0; i<N; i++) {
            int appWidgetId = appWidgetIds[i];
            this.appWidgetManager = appWidgetManager;

            UpdateService.regAppWidgetIds(context, appWidgetId);

            // updatePeriodMillis 옵션 미사용시 아래  이용
             StartUpdate(context, appWidgetId);

            // updatePeriodMillis 옵션 사용시
            //xmlViewParser(context);
        }






        }

        public static void StartUpdate(Context context, int appWidgetsIds) {
        Intent updateIntent = new Intent(context,
UpdateService.class);
        pendingIntent = PendingIntent.getService(context, 0,
                updateIntent, 0);
        if (pendingIntent == null)
            Log.e(TAG, "pendingIntent is null");
        else
            Log.e(TAG, "pendingIntent is not null");

        Calendar cal = Calendar.getInstance();
        // Schedule alarm, and force the device awake for this update
        alarmManager = (AlarmManager)
context.getSystemService(Context.ALARM_SERVICE);

        int delay = 3000; // 10초: 10000 / 30분: 1800000
        alarmManager.setRepeating(AlarmManager.RTC,
cal.getTimeInMillis(), delay, pendingIntent);
    }

        public static void EndUpdate(Context context) {

        alarmManager.cancel(pendingIntent);
        Intent endIntent = new Intent(context, UpdateService.class);
                context.stopService(endIntent);
    }


        public static void xmlViewParser(Context context) {
                // TODO Auto-generated method stub
                RemoteViews remoteViews;
                RemoteViews goViews;
        ComponentName watchWidget;

        // TODO Auto-generated method stub
        remoteViews = new RemoteViews(context.getPackageName(),
                R.layout.simple_widget_layout);
        goViews = new RemoteViews(context.getPackageName(),
                R.layout.simple_widget_layout);
        //....UI처리

 
remoteViews.setTextViewText(R.id.simple_widget_layout_text,"Yes1!");
 
remoteViews.setTextViewText(R.id.simple_widget_layout_text1,"Yes2!");
//
goViews.setTextViewText(R.id.simple_widget_layout_text,"Yes1!");
//
goViews.setTextViewText(R.id.simple_widget_layout_text1,"Yes2!");

        SimpleDateFormat formatStr = new SimpleDateFormat("HH:mm:ss",
Locale.KOREA);
        Date d = new Date();

            String date1 = formatStr.format(d);
 
remoteViews.setTextViewText(R.id.simple_widget_layout_text2,date1);
       //
goViews.setTextViewText(R.id.simple_widget_layout_text2,date1);
        //...UI처리끝

        //reload처리
        Intent intent = new Intent(context, MySimpleWidget.class);
        intent.setAction("CLICK_RELOAD");
        PendingIntent pendingIntent =
PendingIntent.getBroadcast(context, 0,intent, 0);
        remoteViews.setOnClickPendingIntent(R.id.widget,
pendingIntent);
        watchWidget = new ComponentName(context,
MySimpleWidget.class);
        appWidgetManager.updateAppWidget(watchWidget, remoteViews);

        //뻔잉웹뷰로 점핑.. 나중에 메소드레벨로 뽑을것
        Intent intent1 = new Intent(context, English.class);
                PendingIntent pi = PendingIntent.getActivity(context, 0, 
intent1,
Intent.FLAG_ACTIVITY_NEW_TASK);
        goViews.setOnClickPendingIntent(R.id.content, pi);
        watchWidget = new ComponentName(context,
MySimpleWidget.class);

        appWidgetManager.updateAppWidget(watchWidget, goViews);
        }

        /* 위젯이 삭제될때 마다 호출됨.
         * 위젯이 삭제될때마다 서비스를 stop 시킨다. ( 이는  알람도 취소 시킨다는 뜻 )
         *
         * 참고 : 위젯이 삭제 될때마다 서비스가 stop되니 미니티가 실행되건, 알람이 터치되건
         * 사용자 액션이 있을때마다 서비스를 다시 시작 시킨다.
         * @see
android.appwidget.AppWidgetProvider#onDisabled(android.content.Context)
         */
        @Override
        public void onDeleted(Context context, int[] appWidgetIds) {
                super.onDeleted(context, appWidgetIds);
                Log.d(TAG1, "onDeleted");

        }

        @Override
        public void onDisabled(Context context) {
                super.onDisabled(context);
                Log.d(TAG1, "onDisabled");

                EndUpdate(context);
        }
        /* 위젯을 종류에 따라 처음 만들때 호출됨
         * ( 1x1을 처음 생성하면 호출됨, 두번째 생성하면 호출 안됨(이때는 onUpdate가 호출됨.
         * 1x1을 생성한 상태여도 다른종류인 2x1을 생성 하면 호출됨 )
         * 여기서 서비스를 start하여 alarm도 깨운다.
         * @see
android.appwidget.AppWidgetProvider#onEnabled(android.content.Context)
         */
        @Override
        public void onEnabled(Context context) {
                super.onEnabled(context);
                Log.d(TAG1, "onEnabled");

        }

}

---------

service class
public class UpdateService extends Service {

         private static Context context;
         private static int sAppWidgetIds;
         private static final String TAG = "seo";
//       private DateFormat format = SimpleDateFormat.getTimeInstance(
//                  SimpleDateFormat.MEDIUM, Locale.getDefault());



//          public void onStart(Intent intent, int startId) {
//              super.onStart(intent, startId);
//
//              SimpleDateFormat formatStr = new SimpleDateFormat("HHmm",
Locale.KOREA);
//              Date d = new Date();
//
//                  String date1 = formatStr.format(d);
//
//              Log.i(TAG, " Onstart: " + " ... " + date1);
//              MySimpleWidget.xmlViewParser(context);
//          }

        public int onStartCommand(Intent intent, int flags, int startId) {
                super.onStartCommand(intent, flags, startId);

                SimpleDateFormat formatStr = new SimpleDateFormat("HH:mm:ss",
                                Locale.KOREA);
                Date d = new Date();

                String date1 = formatStr.format(d);

                Log.i(TAG, " OnstartCommand: " + " ... " + date1);
                MySimpleWidget.xmlViewParser(context);
                return START_STICKY;
        }

        @Override
        public IBinder onBind(Intent arg0) {
                // TODO Auto-generated method stub
                return null;
        }

        public static void regAppWidgetIds(Context _context, int widgetIds) {
        context = _context;
        sAppWidgetIds = widgetIds;
    }

}

---
log cat

04-15 09:28:16.445: ERROR/ActivityThread(53): Failed to find provider
info for android.server.checkin
04-15 09:28:16.764: ERROR/AndroidRuntime(711): ERROR: thread attach
failed
04-15 09:28:18.373: ERROR/AndroidRuntime(721): Uncaught handler:
thread main exiting due to uncaught exception
04-15 09:28:18.624: ERROR/AndroidRuntime(721):
java.lang.RuntimeException: Unable to start service
com.skcc.english.UpdateService@43d0f780 with Intent { flg=0x4
cmp=com.skcc.english/.UpdateService (has extras) }:
java.lang.NullPointerException
04-15 09:28:18.624: ERROR/AndroidRuntime(721):     at
android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2882)
04-15 09:28:18.624: ERROR/AndroidRuntime(721):     at
android.app.ActivityThread.access$3500(ActivityThread.java:119)
04-15 09:28:18.624: ERROR/AndroidRuntime(721):     at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1926)
04-15 09:28:18.624: ERROR/AndroidRuntime(721):     at
android.os.Handler.dispatchMessage(Handler.java:99)
04-15 09:28:18.624: ERROR/AndroidRuntime(721):     at
android.os.Looper.loop(Looper.java:123)
04-15 09:28:18.624: ERROR/AndroidRuntime(721):     at
android.app.ActivityThread.main(ActivityThread.java:4363)
04-15 09:28:18.624: ERROR/AndroidRuntime(721):     at
java.lang.reflect.Method.invokeNative(Native Method)
04-15 09:28:18.624: ERROR/AndroidRuntime(721):     at
java.lang.reflect.Method.invoke(Method.java:521)
04-15 09:28:18.624: ERROR/AndroidRuntime(721):     at
com.android.internal.os.ZygoteInit
$MethodAndArgsCaller.run(ZygoteInit.java:860)
04-15 09:28:18.624: ERROR/AndroidRuntime(721):     at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
04-15 09:28:18.624: ERROR/AndroidRuntime(721):     at
dalvik.system.NativeStart.main(Native Method)
04-15 09:28:18.624: ERROR/AndroidRuntime(721): Caused by:
java.lang.NullPointerException
04-15 09:28:18.624: ERROR/AndroidRuntime(721):     at
com.skcc.english.MySimpleWidget.xmlViewParser(MySimpleWidget.java:148)
04-15 09:28:18.624: ERROR/AndroidRuntime(721):     at
com.skcc.english.UpdateService.onStartCommand(UpdateService.java:45)
04-15 09:28:18.624: ERROR/AndroidRuntime(721):     at
android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2873)
04-15 09:28:18.624: ERROR/AndroidRuntime(721):     ... 10 more
04-15 09:28:23.025: ERROR/ActivityThread(53): Failed to find provider
info for android.server.checkin
04-15 09:28:23.054: ERROR/gralloc(53): [unregister] handle 0x37a1c8
still locked (state=40000001)
04-15 09:28:33.255: ERROR/AndroidRuntime(727): Uncaught handler:
thread main exiting due to uncaught exception
04-15 09:28:33.274: ERROR/AndroidRuntime(727):
java.lang.RuntimeException: Unable to start service
com.skcc.english.UpdateService@43d0f000 with Intent { flg=0x4
cmp=com.skcc.english/.UpdateService (has extras) }:
java.lang.NullPointerException
04-15 09:28:33.274: ERROR/AndroidRuntime(727):     at
android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2882)
04-15 09:28:33.274: ERROR/AndroidRuntime(727):     at
android.app.ActivityThread.access$3500(ActivityThread.java:119)
04-15 09:28:33.274: ERROR/AndroidRuntime(727):     at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1926)
04-15 09:28:33.274: ERROR/AndroidRuntime(727):     at
android.os.Handler.dispatchMessage(Handler.java:99)
04-15 09:28:33.274: ERROR/AndroidRuntime(727):     at
android.os.Looper.loop(Looper.java:123)
04-15 09:28:33.274: ERROR/AndroidRuntime(727):     at
android.app.ActivityThread.main(ActivityThread.java:4363)
04-15 09:28:33.274: ERROR/AndroidRuntime(727):     at
java.lang.reflect.Method.invokeNative(Native Method)
04-15 09:28:33.274: ERROR/AndroidRuntime(727):     at
java.lang.reflect.Method.invoke(Method.java:521)
04-15 09:28:33.274: ERROR/AndroidRuntime(727):     at
com.android.internal.os.ZygoteInit
$MethodAndArgsCaller.run(ZygoteInit.java:860)
04-15 09:28:33.274: ERROR/AndroidRuntime(727):     at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
04-15 09:28:33.274: ERROR/AndroidRuntime(727):     at
dalvik.system.NativeStart.main(Native Method)
04-15 09:28:33.274: ERROR/AndroidRuntime(727): Caused by:
java.lang.NullPointerException
04-15 09:28:33.274: ERROR/AndroidRuntime(727):     at
com.skcc.english.MySimpleWidget.xmlViewParser(MySimpleWidget.java:148)
04-15 09:28:33.274: ERROR/AndroidRuntime(727):     at
com.skcc.english.UpdateService.onStartCommand(UpdateService.java:45)
04-15 09:28:33.274: ERROR/AndroidRuntime(727):     at
android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2873)
04-15 09:28:33.274: ERROR/AndroidRuntime(727):     ... 10 more
04-15 09:31:01.954: ERROR/AndroidRuntime(735): ERROR: thread attach
failed
04-15 09:31:03.205: ERROR/seo(745): pendingIntent is not null
04-15 09:31:45.994: ERROR/ActivityThread(53): Failed to find provider
info for android.server.checkin
04-15 09:31:46.195: ERROR/AndroidRuntime(753): ERROR: thread attach
failed
04-15 09:31:47.815: ERROR/seo(763): pendingIntent is not null
04-15 09:33:00.283: ERROR/ActivityThread(53): Failed to find provider
info for android.server.checkin
04-15 09:33:00.464: ERROR/AndroidRuntime(771): ERROR: thread attach
failed
04-15 09:33:02.094: ERROR/seo(781): pendingIntent is not null
04-15 09:36:45.415: ERROR/AndroidRuntime(788): ERROR: thread attach
failed
04-15 09:36:55.975: ERROR/ActivityThread(53): Failed to find provider
info for android.server.checkin
04-15 09:36:56.155: ERROR/AndroidRuntime(797): ERROR: thread attach
failed

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to