public class BleScan

  1. Object
  2. Observable
  3. AsyncResource<Boolean>
  4. BleScan

Live handle of a running BLE scan returned by BluetoothLE.startScan(ScanSettings, ScanListener). Any number of scans may run concurrently – each handle only sees advertisements passing its own filters.

As an AsyncResource<Boolean> the handle resolves when the scan ends: with true after a normal stop(), or with a BluetoothException when the OS aborted the scan. cancel() is equivalent to stop().

Constructors

protected BleScan()Created by BluetoothLE; application code receives instances from startScan.

Methods

public void stop()Stops this scan.
public boolean isActive()true while the scan is running.
public boolean cancel(boolean mayInterruptIfRunning)Equivalent to stop().
protected void onStop()Hook for BluetoothLE to unregister the handle and stop the platform scan when it was the last one; invoked exactly once from stop().

Inherited nested types

Inherited methods

Constructor details

BleScan

protected BleScan()
Created by BluetoothLE; application code receives instances from startScan.

Method details

stop

public void stop()
Stops this scan. The handle resolves with true; the underlying platform scan keeps running while other handles remain active. Calling stop() on an already ended scan is a no-op.

isActive

public boolean isActive()
true while the scan is running.

cancel

public boolean cancel(boolean mayInterruptIfRunning)
Equivalent to stop().

Returns

True if the resource loading was cancelled. False if the loading was already done.

Cancellation notifies observers, which is how a waiter learns the resource became terminal. It used to call setChanged() and stop there, leaving the flag set with nothing notified: a thread inside get() adds an observer, checks isDone(), and then waits, so a cancel landing after that check woke nobody and the waiter blocked forever on a resource that had already finished.

It deliberately does not run the callbacks registered through ready(SuccessCallback) or except(SuccessCallback). Cancelling means the caller has stopped listening, and publishing to it anyway would contradict a contract the rest of the framework is built on and tests – see the AI language and vision suites, which assert that a cancelled operation delivers neither a value nor an error even when the backend answers afterwards. Observers are the internal wake mechanism for get() and waitFor(); they are not the application’s callbacks.

One consequence worth knowing: cleanup wired through onResult(AsyncResult) does not run on cancellation either. Anything that must be released has to be released by whoever owns it. A per-operation timeout timer, for instance, survives until its deadline and then retires itself on finding the resource already done.

onStop

protected void onStop()
Hook for BluetoothLE to unregister the handle and stop the platform scan when it was the last one; invoked exactly once from stop().