5

I try to write my first widget application and i got a problem. So, i have 2 arrows: switch to left and switch to right. For both of them I want to use a single Service, which changes the view of my homescreen widget according direction of arrow. For distinguish the direction of arrow i put an extra data to each intent i use. This is my sample code:

    
RemoteViews remoteViews =
     new RemoteViews(context.getPackageName(),
      R.layout.presentation_layout);

 Intent updateServiceIntent1 = new Intent(context, UpdateService.class);
 updateServiceIntent1.putExtra("com.mycompany.direction", 1);
 PendingIntent updateServicePendingIntent1 =
     PendingIntent.getService(context, 0, updateServiceIntent1,
      PendingIntent.FLAG_UPDATE_CURRENT);
 //Action when we touch left arrow
 remoteViews.setOnClickPendingIntent(R.id.left,
  updateServicePendingIntent1);

 Intent updateServiceIntent2 = new Intent(context, UpdateService.class);
 updateServiceIntent2.putExtra("com.mycompany.direction", 0);
 PendingIntent updateServicePendingIntent2 =
     PendingIntent.getService(context, 0, updateServiceIntent2,
      PendingIntent.FLAG_UPDATE_CURRENT);
 //Action when we touch right arrow
 remoteViews.setOnClickPendingIntent(R.id.right,
  updateServicePendingIntent2);

 ComponentName thisWidget =
     new ComponentName(context, HelperWidget.class);
 AppWidgetManager manager = AppWidgetManager.getInstance(context);
 manager.updateAppWidget(thisWidget, remoteViews);

In Service I do the next:


@Override
    public void onStart(Intent intent, int startId) {

   Log.i(TAG, "direction " + intent.getIntExtra("com.mycompany.direction", -1) + "");

}

So, in debug i always got direction 0. But i want to get direction 1 when i touch left arrow and direction 0 when i touch right arrow. Could you help me in this problem? Thanks.

anyoneguy
  • 154
  • 1
  • 2
  • 8
  • I answered a similar question [here](http://stackoverflow.com/questions/4011178/multiple-instances-of-widget-only-updating-last-widget/4011431#4011431) – Snailer Oct 31 '10 at 20:44
  • Thanks to you and sorry for posting similar question. So, could please tell me where you looked up this information? – anyoneguy Nov 04 '10 at 10:35
  • Heh, I didn't look it up, I also asked this question here. Just spreading the good word ;) – Snailer Nov 04 '10 at 21:16

0 Answers0