BroadcastReceiverWithCallbacks


public abstract class BroadcastReceiverWithCallbacks<T extends CallbackReceiver> extends BroadcastReceiver implements CallbackReceiver


Extend this broadcast receiver to be able to receive callbacks as well as normal broadcasts. Ensure that you call the super of onReceive when the action is ACTION_BROADCAST_CALLBACK.

Parameters
<T extends CallbackReceiver>

Should be specified as the root class (e.g. class X extends BroadcastReceiverWithCallbacks\)

Summary

Constants

static final String
ACTION_BROADCAST_CALLBACK = "androidx.remotecallback.action.BROADCAST_CALLBACK"

The action used for incoming RemoteCallbacks.

Public constructors

Public methods

T

Creates a RemoteCallback that will call the method with method specified with the arguments specified when triggered.

void
onReceive(Context context, Intent intent)

Inherited methods

From android.content.BroadcastReceiver
final void
final void
final boolean
final boolean
final int
final String
final Bundle
getResultExtras(boolean makeMap)
String
int
final BroadcastReceiver.PendingResult
final boolean
final boolean
IBinder
peekService(Context myContext, Intent service)
final void
setDebugUnregister(boolean debug)
final void
setOrderedHint(boolean isOrdered)
final void
setResult(int code, String data, Bundle extras)
final void
setResultCode(int code)
final void
final void

Constants

ACTION_BROADCAST_CALLBACK

Added in 1.0.0-alpha02
public static final String ACTION_BROADCAST_CALLBACK = "androidx.remotecallback.action.BROADCAST_CALLBACK"

The action used for incoming RemoteCallbacks.

Public constructors

BroadcastReceiverWithCallbacks

Added in 1.0.0-alpha02
public BroadcastReceiverWithCallbacks()

Public methods

createRemoteCallback

Added in 1.0.0-alpha02
public T createRemoteCallback(Context context)

Creates a RemoteCallback that will call the method with method specified with the arguments specified when triggered. Only methods tagged with RemoteCallable can be used here. This method returns a stub implementation of the class calling it to record the arguments/method being used. This should only be used in a chain of 2 calls, starting with createRemoteCallback(), then followed up with a call to any method tagged with RemoteCallable.

    createRemoteCallback().callMyMethod("My arguments", 43, 2.4)
             .toPendingIntent(context);
    \@RemoteCallable
    public RemoteCallback callMyMethod(String argStr, int argInt, double argDouble) {
        ...
        return RemoteCallback.LOCAL;
    }

onReceive

Added in 1.0.0-alpha02
public void onReceive(Context context, Intent intent)