# addObserver

open fun addObserver(observer: Observer)

Add a observer to be called when network status, launching status or user status is changed.

Example Usage:

    public class MyObserverManager {
        ...
        private void handlingObserverMessage() {
            Gamebase.addObserver(new Observer() {
                 @Override
                 public void onLaunchingInfoUpdate(ObserverMessage message) {
                     String typeOfMessage = message.type;
                     Map<String, Object> dataMap = message.data;

                     if (typeOfMessage.equalsIgnoreCase(ObserverMessage.Type.LAUNCHING)) {
                         int code = (int) dataMap.get("code");
                         String messageString = (String) dataMap.get("message");
                         Log.d(TAG, "Update launching status: " + code + ", " + messageString);
                     } else if (typeOfMessage.equalsIgnoreCase(ObserverMessage.Type.HEARTBEAT)) {
                         Log.d(TAG, "Heartbeat changing : " + dataMap);
                     } else if (typeOfMessage.equalsIgnoreCase(ObserverMessage.Type.NETWORK)) {
                         Log.d(TAG, "Network changing : " + dataMap);
                     } else {
                         Logger.d(TAG, "Something gonna be changing : " + dataMap);
                     }
                 }
             });
         }
         ...
    }

Content copied to clipboard

#### Since

Added 1.8.0.

#### Parameters

observer

The callback that will run.

#### See also

Observer