tree: ac8f5d0396c90e44b4dec152a5c0b7c2c28665d6 [path history] [tgz]
  1. processor/
  2. remotecallback/

Remote Callbacks

Remote callbacks provide a wrapper that makes it easier for developers to provide a PendingIntent. Generally those writing widgets, notifications, and more recently slices, have the fun of writing code that looks like this relatively frequently.

public class MyReceiver extends BroadcastReceiver {
  final String ACTION_MY_CALLBACK_ACTION = "...";
  final String EXTRA_PARAM_1 = "...";
  final String EXTRA_PARAM_2 = "...";

  public PendingIntent getPendingIntent(Context context, int value1, int value2) {
    Intent intent = new Intent(context, MyReceiver.class);
    intent.putExtra(EXTRA_PARAM_1, value1);
    intent.putExtra(EXTRA_PARAM_2, value2);
    return PendingIntent.getBroadcast(context, 0, intent,

  public void onReceive(Context context, Intent intent) {
    if (ACTION_MY_CALLBACK_ACTION.equals(intent.getAction())) {
      int param1 = intent.getIntExtra(EXTRA_PARAM_1, 0);
      int param2 = intent.getintExtra(EXTRA_PARAM_2, 0);
      doMyAction(param1, param2);

  public void doMyAction(int value1, int value2) {

The goal of Remote Callbacks is to remove as much of that fun as possible and let you get right down to business. Which looks like this much abbreviated version.

public class MyReceiver extends BroadcastReceiverWithCallbacks<MyReceiver> {
  public PendingIntent getPendingIntent(Context context, int value1, int value2) {
    return createRemoteCallback(context).doMyAction(value1, value2)

  public RemoteCallback doMyAction(int value1, int value2) {
    return RemoteCallback.LOCAL;

See CallbackReceiver and its linked documentation for more API details.