On Wed, Aug 26, 2015 at 10:17 AM, Ningje Chen (Jim Chen) <[email protected]>
wrote:
> Hi all,
>
> A common pattern on Android when we handle a UI event sent from Gecko is
> to register a GeckoEventListener/NativeEventListener, and then immediately
> post a Runnable to the UI thread to actually handle the UI event (e.g.
> "Prompt:Show").
>
> I recently landed bug 991167, which added BundleEventListener to make it
> easier to handle an event on the UI thread or the background thread. Simply
> implement BundleEventListener in your class instead of NativeEventListener,
> and then provide a handleMessage override:
>
> @Override
> void handleMessage(String event, Bundle message, EventCallback callback)
> {
> // "message" is a copy of the original JSON message with the same
> properties.
> }
>
> Finally, register the event through
> EventDispatcher.getInstance().registerUiThreadListener or
> EventDispatcher.getInstance().registerBackgroundThreadListener.
> Unregistering follows the same pattern. You can use BundleEventListener
> alongside existing GeckoEventListener/NativeEventListener. Hope this proves
> useful!
>
> Here's a summary of the three event listener interfaces that are currently
> available,
>
> Interface: GeckoEventListener (deprecated; use NativeEventListener)
> Message format: JSONObject
> Event dispatched on: Gecko thread
> Registration: EventDispatcher.registerGeckoThreadListener
> Unregistration: EventDispatcher.unregisterGeckoThreadListener
>
> Interface: NativeEventListener
> Message format: NativeJSObject
> Event dispatched on: Gecko thread
> Registration: EventDispatcher.registerGeckoThreadListener
> Unregistration: EventDispatcher.unregisterGeckoThreadListener
>
> Interface: BundleEventListener
> Message format: Bundle
> Event dispatched on: UI thread / background thread
> Registration: EventDispatcher.registerUiThreadListener,
> EventDispatcher.registerBackgroundThreadListener
> Unregistration: EventDispatcher.unregisterUiThreadListener,
> EventDispatcher.unregisterBackgroundThreadListener
>
This is really nice. Thanks Jim!
Nick
_______________________________________________
mobile-firefox-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/mobile-firefox-dev