2012-07-03 3 views
0

위젯이 3 분마다 인터넷에서 데이터를 가져오고 일부는 위젯에 직접 표시되고 다른 일부는 SharedPreferences에 저장되므로 사용자가 위젯을 탭하면 그 정보는 대화 상자로 나타납니다. 두 개 이상의 위젯 실행을 가진 경우, 아무리 내가 로그를 클릭하는 위젯)합니다 (appWidgetId이 항상서비스가있는 데이터를 가져 오는 Android 위젯

내 문제는 내가 위젯의 setOnClickPendingIntent를 선언하고있어 방법이있을 것 같다 그들 중 하나에서 오는 말한다. 필자는 데이터를 가져 오기 직전에 서비스 내부에서이를 수행하고 모든 서비스 (위젯)에 의해 동일한 서비스가 실행되기 때문에 모든 위젯은 마지막 서비스가 실행 된 PendingIntent를 가져옵니다.

public class WidgetService extends Service 
{ 
@Override 
    public void onStart(Intent intent, int startId) 
    { 
      Intent intentUmbrales = new Intent(context, LaunchUmbralesDialog.class); 
      intentUmbrales.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); 
      PendingIntent pendingIntentUmbrales = PendingIntent.getActivity(context,0,intentUmbrales,0); 

      // Get the layout for the App Widget and attach an on-click listener to the button 
      RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget); 

     // views.setOnClickPendingIntent(R.id.energia_widget, pendingIntentImei); 
      views.setOnClickPendingIntent(R.id.imageLogo_widget, pendingIntentUmbrales); 
     //..then I fetch data, store the rest in SharedPreferences and update widget remoteViews 
    } 
} 

어떻게 피할 수 있습니까? 어떻게하면 각 위젯을 겹쳐서 각각의 "버튼"을 만들 수 있습니까? 또한 이미 AppWidgetProvider의 onUpdate() 메소드에서 해당 PendingIntents를 선언하려고 시도했음을 유의하십시오. (메서드에 의해 지정된 배열의 모든 appWidgetId에 대한 루프 내부)

미리 감사드립니다!

안부, 로드리고. .setOnClickPendingIntent()를 선언 할 때는

답변

0

는 먼저 각 위젯은 고유 ID를 얻고 그들이 엉망이되지 않도록하는

Uri data = Uri.withAppendedPath(
        Uri.parse(URI_SCHEME + "://widget/id/") 
        ,String.valueOf(appWidgetId)); 
       intent.setData(data); 

의도

에 추가!

관련 문제