Note that there are some explanatory texts on larger screens.

plurals
  1. PORemoteViews and setOnClickPendingIntent
    primarykey
    data
    text
    <p>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:</p> <pre><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); </code></pre> <p>In Service I do the next:</p> <pre><code> @Override public void onStart(Intent intent, int startId) { Log.i(TAG, "direction " + intent.getIntExtra("com.mycompany.direction", -1) + ""); } </code></pre> <p>So, in debug i always got <strong>direction 0</strong>. But i want to get <strong>direction 1</strong> when i touch left arrow and <strong>direction 0</strong> when i touch right arrow. Could you help me in this problem? Thanks.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload