# User Controller ## Push Token Registration via *UserController* API Note: [UserController](https://download.sinch.com/android/latest/reference/com/sinch/android/rtc/UserController.html) provides a way, independently from the `SinchClient` lifecycle, to register a user for incoming calls via push notifications. You can also use it to unregister a push token if receiving incoming calls is no longer desirable (example on logout, or changing users). Sinch SDK supports both currently available major Push Notification platforms on Android - [Google's Firebase Cloud Messages](/docs/in-app-calling/android/push-notifications#google-fcm-push-notifications) (later `FCM Push`) and [Huawei Mobile Services Push Notifications](/docs/in-app-calling/android/push-notifications#huawei-hms-notifications) (later `Huawei Push` or `HMS Push`). `UserController` provides a way to explicitly register the push token and get assurance that the push token is indeed registered. As an example: - The application is designed to receive calls only and thus must register the push token with the Sinch backend on each start. Even though it's usually best to terminate `SinchClient` as soon as the registration concludes to free up resources, in this situation, the application should be notified by a specific callback on the registration result. - The application detects that FCM/HMS Push token is invalidated and should be refreshed and re-registered with Sinch backend. Both situations should be handled using the [UserController](https://download.sinch.com/android/latest/reference/com/sinch/android/rtc/UserController.html), which can be used independently from the *SinchClient* (it doesn't require creating and starting the *SinchClient*). ### Create UserController ```kotlin fun createUserController(String userId): UserController { // See 'Push notifications' page to see what a push configuration is and how to implement your 'createPushConfiguration' function val pushConfiguration = createPushConfiguration() return UserController.builder() .context(getApplicationContext()) .applicationKey("") .userId("") .environmentHost("ocra.api.sinch.com") .pushConfiguration(pushConfiguration) .build() } ``` Note: Your application can be built to support both FCM and HMS, but each *application instance* should register itself towards Sinch backend to receive Push Notification using either one way or another. User registration is a two-step process, where the first the step is registering *user* (after which you can make outgoing calls using the *SinchClient*), and the second is registering the push token for receiving incoming calls via FCM/HMS Push notifications. Each step has correspondent *success* and *failure* callbacks. The one you're mostly interested is the *tokenRegistered*. After receiving it, you can terminate and close the application and be sure that incoming calls will be received. ![Token-based User Registration (FCM case)](/assets/20210125-user_and_push_registration.pu.36acaf47f8299b776bae4aa6499c270025c8c7734824a3d66d4a2c9b516c05bb.5f3ff73a.png) The action flow diagram of the *User* registration via *UserController* is provided below. *UserController*'s callbacks are highlighted in pale blue. ![Registering User via UserController](/assets/20201006-usercontroller-callbacks.pu.065cb8a06c3cc121756b7ae26ef329d125c19f125481af0767b14882a045db61.5f3ff73a.png) Note: User Controller requires signed registration token the same way as it's required by the SinchClient for the first time. Provide it via [ClientRegistration.register()](https://download.sinch.com/android/latest/reference/com/sinch/android/rtc/ClientRegistration.html) callback in response to *onCredentialsRequired()*. See more information about authentication [here](/docs/in-app-calling/android/application-authentication). When both conditions: - SinchClient is started (optional, see the note below). - Push token is registered. are met, the authentication process has finished and example UI can advance. Note: You don't need to start *SinchClient* if you only want to receive calls. Note: It's safe to close application right after receiving *tokenRegistered()* callback - you'll keep receiving incoming calls unless you *force stop* the application or unregister the push token using *UserController*. ### Push Token Unregistration via *UserController* API When you want to *logout* and stop receiving incoming calls via push, unregister the push token using *UserController*: ```kotlin // Parameter is PushTokenUnregistrationCallback. userController.unregisterPushToken(this) ```