# globalEvent 0.14

globalEvent are used to listen for persistent events, such as changes in positioning information, gyroscopes, and so on. A global event is a secondary API that requires additional APIs to work with.

# Built-in global events

You can specify the event name as WXApplicationDidBecomeActiveEvent or WXApplicationWillResignActiveEvent to obtain application becoming foreground or background, so that you can pause your video or music at this time.

var globalEvent = weex.requireModule('globalEvent');
globalEvent.addEventListener("WXApplicationDidBecomeActiveEvent", function (e) {
  • WXApplicationDidBecomeActiveEvent, fired while application did become foreground
  • WXApplicationWillResignActiveEvent, fired while application will become background



This feature only works on iOS and Android platforms, it doesn't work on Web. Obtain your weex platform on weex page

# Fire a global event


Map<String,Object> params=new HashMap<>();
mWXSDKInstance.fireGlobalEventCallback("geolocation", params);


[weexInstance fireGlobalEvent:@"geolocation" params:@{@"key":@"value"}];


# addEventListener

Register global event.

# addEventListener(eventName, callback)

  • @eventName, string, the name of the event you want to listen to.
  • @callback, function, the callback function after executing this action.
var globalEvent = weex.requireModule('globalEvent');
globalEvent.addEventListener("geolocation", function (e) {
	console.log("get geolocation")

# removeEventListener

Remove global event

# removeEventListener(eventName)

  • @eventName, the event name to unregister.
var globalEvent = weex.requireModule('globalEvent');
Last Updated: 8/15/2022
Excellent docUnusable doc