5

대기중인 의도가 2 개인 AppWidget이 있습니다. 대부분의 경우 작동하지만 잠시 후 응답을 멈 춥니 다. 내가 정확히 알아 낸 점은 Launcher를 다시 시작한 후에는 Launcher Pro를 사용하고 Launcher Pro를 사용하고 때로는 설정을 사용하여 다시 시작해야하므로 장애가 발생한다는 것입니다. 그 후에는 전혀 작동하지 않습니다. 여기 실행기를 다시 시작한 후 AppWidget PendingIntent가 작동하지 않습니다.

onRecieve()onUpdate() 방법이 있습니다 : 나는 서비스의 의도 퍼팅에 대해 읽고

public void onReceive(Context context, Intent intent) 
{ 
    super.onReceive(context, intent); 
    String action = intent.getAction(); 
    if(action.equals("android.tristan.widget.digiclock.CLICK")) 
    { 
     PackageManager packageManager = context.getPackageManager(); 
     Intent alarmClockIntent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER); 

     String clockImpls[][] = { 
       {"HTC Alarm Clock", "com.htc.android.worldclock", "com.htc.android.worldclock.AlarmClock" }, 
       {"Standar Alarm Clock", "com.android.deskclock", "com.android.deskclock.AlarmClock"}, 
       {"Froyo Nexus Alarm Clock", "com.google.android.deskclock", "com.android.deskclock.DeskClock"}, 
       {"Moto Blur Alarm Clock", "com.motorola.blur.alarmclock", "com.motorola.blur.alarmclock.AlarmClock"} 
     }; 

     boolean foundClockImpl = false; 

     for(int i=0; i<clockImpls.length; i++) { 
      String vendor = clockImpls[i][0]; 
      String packageName = clockImpls[i][1]; 
      String className = clockImpls[i][2]; 
      try { 
       ComponentName cn = new ComponentName(packageName, className); 
       ActivityInfo aInfo = packageManager.getActivityInfo(cn, PackageManager.GET_META_DATA); 
       alarmClockIntent.setComponent(cn); 
       foundClockImpl = true; 
      } catch (NameNotFoundException e) { 
       Log.d(LOGTAG, "Error," + vendor + " does not exist"); 
      } 
     } 

     if (foundClockImpl) { 
     Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); 
     vibrator.vibrate(50); 
     final RemoteViews views = new RemoteViews(context.getPackageName(), layoutID); 
     views.setOnClickPendingIntent(R.id.TopRow, PendingIntent.getActivity(context, 0, new Intent(context, DigiClock.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK), PendingIntent.FLAG_UPDATE_CURRENT)); 
     AppWidgetManager.getInstance(context).updateAppWidget(intent.getIntArrayExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS), views); 
     alarmClockIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
     context.startActivity(alarmClockIntent);  
    } 
    } 
} 

     public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { 
super.onUpdate(context, appWidgetManager, appWidgetIds); 
    context.startService(new Intent(UpdateService.ACTION_UPDATE)); 
    context.startService(new Intent(context, ScreenUpdateService.class)); 
    final int Top = appWidgetIds.length; 
    final int Bottom = appWidgetIds.length; 
    for (int i=0; i<Top; i++) 
    { 
    int[] appWidgetId = appWidgetIds; 
    final RemoteViews top=new RemoteViews(context.getPackageName(), layoutID); 
    Intent clickintent=new Intent("android.tristan.widget.digiclock.CLICK"); 
    PendingIntent pendingIntentClick=PendingIntent.getBroadcast(context, 0, clickintent, 0); 
    top.setOnClickPendingIntent(R.id.TopRow, pendingIntentClick); 
    appWidgetManager.updateAppWidget(appWidgetId, top); 
} 
for (int i=0; i<Bottom; i++) 
{ 
    int[] appWidgetId = appWidgetIds; 
    RemoteViews bottom=new RemoteViews(context.getPackageName(), layoutID); 
    Intent clickintent=new Intent("android.tristan.widget.digiclock.CLICK_2"); 
    PendingIntent pendingIntentClick=PendingIntent.getBroadcast(context, 0, clickintent, 0); 
    bottom.setOnClickPendingIntent(R.id.BottomRow, pendingIntentClick); 
    appWidgetManager.updateAppWidget(appWidgetId, bottom); 
} 
} 

하지만했으나 실패했다. 어떤 도움을 주셔서 감사합니다.

+0

'super.onUpdate();'와 (과) 무슨 관계가 있습니까? http://androidxref.com/4.4.4_r1/xref/frameworks/base/core/java/android/appwidget/AppWidgetProvider.java#113 소스에 따라 아무 것도하지 않습니다. – faizal

+0

모든 위젯에 대해'appWidgetManager.updateAppWidget()'을 루프로 호출 할 필요가 없습니다. 정수 배열을 허용합니다. 따라서'appWidgetManager.updateAppWidget (appWidgetId, top) '대신 여러 번'appWidgetManager.updateAppWidget (appWidgetIds, top)'를 한 번 호출하면됩니다. – faizal

답변

4

필자가 작성한대로 here은 RemoteView의 단일 인스턴스 만 생성해야합니다.

+0

사실, 단일 인스턴스를 만들면 결국 위젯이 무너지게됩니다. 원격보기로 전송 된 각 명령에 따라 메모리가 증가하므로 – htafoya