[ Web Proxy ]
URL:
Viewing: http://developer.android.com/reference/android/hardware/TriggerEventListener [Back]  [Original]

TriggerEventListener  |  API reference  |  Android Developers Skip to main content
Essentials Design & Plan Develop Google Play Blog
Search:
Android Studio
Android Developers [Android Developers]
Stay organized with collections Save and categorize content based on your preferences.

TriggerEventListener


public abstract class TriggerEventListener
extends Object

java.lang.Object
   ↳ android.hardware.TriggerEventListener


This class is the listener used to handle Trigger Sensors. Trigger Sensors are sensors that trigger an event and are automatically disabled. Sensor.TYPE_SIGNIFICANT_MOTION is one such example.

SensorManager lets you access the device's sensors. Get an instance of SensorManager by calling Context.getSystemService() with the argument Context.SENSOR_SERVICE.

Here's an example setup for a TriggerEventListener:

class TriggerListener extends TriggerEventListener {
    public void onTrigger(TriggerEvent event) {
         // Do Work.

    // As it is a one shot sensor, it will be canceled automatically.
    // SensorManager.requestTriggerSensor(this, mSigMotion); needs to
    // be called again, if needed.
    }
}
public class SensorActivity extends Activity {
    private final SensorManager mSensorManager;
    private final Sensor mSigMotion;
    private final TriggerEventListener mListener = new TriggerEventListener();

    public SensorActivity() {
        mSensorManager = (SensorManager)getSystemService(SENSOR_SERVICE);
        mSigMotion = mSensorManager.getDefaultSensor(Sensor.TYPE_SIGNIFICANT_MOTION);
    }

    protected void onResume() {
        super.onResume();
        mSensorManager.requestTriggerSensor(mListener, mSigMotion);
    }

    protected void onPause() {
        super.onPause();
        // Call disable to ensure that the trigger request has been canceled.
        mSensorManager.cancelTriggerSensor(mListener, mSigMotion);
    }

}

See also:

Summary

Public constructors

TriggerEventListener()

Public methods

abstract void onTrigger(TriggerEvent event)

The method that will be called when the sensor is triggered.

Inherited methods

Public constructors

TriggerEventListener

public TriggerEventListener ()

Public methods

onTrigger

Added in API level 18
public abstract void onTrigger (TriggerEvent event)

The method that will be called when the sensor is triggered. Override this method in your implementation of this class.

Parameters
event TriggerEvent: The details of the event.

Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.

Last updated 2026-08-03 UTC.

[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2026-08-03 UTC."],[],[]]

Web Proxy Viewer  |  New URL  |  Original Page