Suppose I have created an instance of RemoteViews
and it contains two Button
s. I want when user clicks these buttons a Service
(or a BroadcastReceiver
or something else ) handles this click. As I know so far, there is two ways for achieve this purpose :
Assign different Actions to these Buttons for example
ACTION_BTN_1_CLICKED
and
ACTION_BTN_2_CLICKED
and then retrieve the action in the Service viaintent.getAction()
and finally service does a appropriate taskPut some extra into the Intent object which is enclosed via
PendingIntent
for example:intent.putStringExtra("which_button", "btn1"); // for Button 1
and
intent.putStringExtra("which_button", "btn2"); // for Button 2
In the other hand in Service I can distinguish this signal via
intent.getExtras().getString("which_button")
Now my question is which approach is better at least in practice? Thanks