Jump to content
Sign in to follow this  
Fabian1648

[Android]How to make an event listener?

Recommended Posts

Hello,

 

Is there a solution with FMX to have an events listener that detects all the events that are triggered in an app?

 

Thanks for all

 

Edited by Fabian1648

Share this post


Link to post

You could look into TMessage and TMessageManager,  which is used internally a lot, but probably not all events.

Anyway, you could build something around this, also for custom events,  it works quite reliable . 

Share this post


Link to post
On 5/29/2021 at 8:07 PM, Fabian1648 said:

Is there a solution with FMX to have an events listener that detects all the events that are triggered in an app?

By "events", if you mean things like whether the app became active, entered the background etc, you can have the app subscribe to TApplicationEventMessage:

 

http://docwiki.embarcadero.com/Libraries/Sydney/en/FMX.Platform.TApplicationEventMessage

 

Use TMessageManager to subscribe to the event, e.g:

  TMessageManager.DefaultManager.SubscribeToMessage(TApplicationEventMessage, ApplicationEventMessageHandler);

..and to unsubscribe when you no longer wish to receive the messages:

  TMessageManager.DefaultManager.Unsubscribe(TApplicationEventMessage, ApplicationEventMessageHandler);

Example handler:

procedure TMyClass.ApplicationEventMessageHandler(const Sender: TObject; const M: TMessage);
var
  LMessage: TApplicationEventMessage;
begin
  LMessage := TApplicationEventMessage(M);
  case LMessage.Value.Event of
    TApplicationEvent.BecameActive:
      DoAppBecameActive;
    TApplicationEvent.EnteredBackground:
      DoAppEnteredBackground;
    // etc
  end;
end;

 

  • Like 1
  • Thanks 2

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×