2012-04-18 1 views
1

위젯이있는 앱이 있습니다. 위젯으로 앱을 시작하고 싶지만 부팅 후 내 위젯이 클릭에 응답하지 않습니다. 앱을 정상적으로 시작한 후에 만 ​​(다시 닫으면) 위젯이 위젯 자체의 클릭에 응답하기 시작합니다.부팅 후 내 Android 2.3 위젯이 클릭에 응답하지 않는 이유는 무엇입니까?

이것은 어떻게 설정의 AppWidgetProvider와 위젯 :

public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) 
{ final int ids = appWidgetIds.length; 

    for(int i=0;i<ids;i++) 
    { int appWidgetId = appWidgetIds[i]; 

     Intent intent = new Intent(context, TestReceiver.class);    
     intent.setAction(ACTION_WIDGET_RECEIVER); 
     intent.setClassName(TestReceiver.class.getPackage().getName(), TestReceiver.class.getName()); 

     PendingIntent pi = PendingIntent.getBroadcast(context, 0, intent, 0); 

     RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget); 

     views.setOnClickPendingIntent(R.id.widget_root, pi); 
     views.setTextViewText(R.id.widgetclock, "Loading..."); 

     appWidgetManager.updateAppWidget(appWidgetId, views); 
    } 
} 

내가 한 번 이상 먼저 시작하지 않고도 내 응용 프로그램은 부팅 후 위젯에 클릭을 등록되도록 변경해야합니까?

+0

왜 * 및 * a 클래스를 사용하고 있습니까? 일반적으로 둘 중 하나를 사용합니다. – CommonsWare

+0

그렇지 않으면 작동하지 않기 때문입니다. – HardCoder

+0

"그렇지 않으면 작동하지 않기 때문에"- 다른 모든 사람들에게 유용합니다. 어쩌면'BroadcastReceivers'와'Intent' 시스템이 어떻게 작동하는지 배우는 시간을 갖고 나서 앱 위젯을 쓰려고 노력해야 할 것입니다. – CommonsWare

답변

0

BOOT 브로드 캐스트에 응답하는 BroadcastReceiver를 생성하고 위젯의 PendingIntent를 재설정하십시오. 장치 재부팅시 Widget PendingIntents가 존속한다고 생각하지 않습니다.

+0

재설정을 시도했지만 작동하지 않았습니다. – HardCoder