Android listen for all events in application

Related searches

I want to listen for all user events on the phone - like onTouch, onClick, onMenuItemClicked etc. For this, I have made a super class which extends activity, and all activities extend from this class.

public class TopActivity extends Activity {


public class screen1 extends TopActivity {


For listening to events I have implemented the listener functions in the super class like these - onTouch(), onClick(), onMenuOpened(), etc. All these call the same function which has the code that should run when any event occurs.

The problem is that I would have to implement every listener. Is there a better way to do this? I just want to run the same piece of code when ever there is any user event in the application.

There is no OnEventListener interface. You will need to implement each one you want to listen.

You can do it this way:

public class TopActivity extends Activity implements OnClickListener, 
  OnTouchListener, OnKeyListener, OnLongClickListener /*etc*/ {

  public void onClick() {

  public boolean onKey(View v, int keyCode, KeyEvent event) {

  // etc

Input events overview, So I recommend to refer official documentation for Android application Though there are several tricky ways to register your event listener for any event, but I'm� Android Listeners are used to capture events. When, for instance, the user interacts with the Android system by clicking on a button, the Listeners would prompt the underlying activity to do the task associated with the button click. Therefore, whenever you want the Android system to perform a task (when an event occurs), Listeners are at work.

We had the same problem, so we developed the Android HCI Extractor some months ago. It was made to track and monitor the user and system interaction events in multimodal applications (e.g. touch, keypresses, scroll, number of elements provided by the system, etc.)

It is very easy to integrate and to use. In the tutorials you can see that only a few lines of code are needed. Moreover, with this solution you do not have to implement all listeners; you only need to add code into the methods in the /android.hci.extractor/src/org/mmi/facades/ class.

Here the links: - Android HCI Extractor code: - MIM project (including tutorials about the tool integration and usage):

I hope it helps you!!

Android Input Events (Event Listeners, Event Handling), I want to listen for all user events on the phone - like onTouch, onClick, onMenuItemClicked etc. For this, I have made a super class which extends activity, and� Android bridges the gap between the user interface and the back end code of the application through the concepts of event listeners and callback methods. The Android View class defines a set of event listeners, which can be registered on view objects. Each event listener also has associated with it a callback method.

There are some methods in the Activity class you can override that may help. I used this when I had to intercept all events for all view controls in order to reset an idle timeout countdown. It sounds like you have a similar wide-scoped need to handle all events similarly, so this might be just what you need:



Android - Event Handling, Event Listening in Android development is largely centered around the View object. View Event Listeners. Any View (Button, TextView, etc) has many event� An application listens for specific broadcast intents by registering a broadcast receiver. Broadcast receivers are implemented by extending the Android BroadcastReceiver class and overriding the onReceive () method. The broadcast receiver may then be registered, either within code (for example within an activity), or within a manifest file.

Create a base activity class that all activities extend and add the following snippet to the base activity

public boolean dispatchTouchEvent(MotionEvent ev) {
    if (ev.getAction() == MotionEvent.ACTION_DOWN) { // If you only want the touch events 
        doYourAction(); //Your action for each touch event
    return super.dispatchTouchEvent(ev);

Android listen for all events in application, System broadcasts are sent to all apps that are subscribed to receive the event. The broadcast message itself is wrapped in an Intent object whose action string identifies the event that occurred (for example android.intent.action.AIRPLANE_MODE). The intent may also include additional information bundled into its extra field.

Basic Event Listeners, An event listener is an interface in the View class that contains a single callback method. These methods will be called by the Android framework when the View to which the listener has been registered is triggered by user interaction with the item in the UI. Included in the event listener interfaces are the following callback methods: onClick()

: "Beginning with Android 8.0 (API level 26), the system imposes additional restrictions on manifest-declared receivers. If your app targets API level 26 or higher, you cannot use the manifest to declare a receiver for most implicit broadcasts (broadcasts that do not target your app specifically)." – Tobias Uhmann Mar 2 '18 at 18:13

Other answers point out listening for ACTION_PACKAGE_ADDED and ACTION_PACKAGE_REPLACED broadcasts. That is fine for Android 7.1 and lower. On Android 8.0+, you cannot register for those broadcasts in the manifest.

  • Check my answer here…