views:

53

answers:

1

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.

+1  A: 

I answered a similar question here

Snailer