Singleton class for HMS Account Kit -It is Easy to Sign-Out from any page
Introduction
Nowadays a good number of mobile applications are using login system. Such applications user need to sign in to get core app features. HMS Account Kit helps the developer to provide simple, secure, and quick sign-in and authorization functions. In this article we are going to discuss how we can use Singleton class to establish HMS Account Kit.
You have to add all the integration steps as mentioned in HMS Document.
The code for singleton class is added below. Here the method init() is used to perform all the initialization operation , and used AccountAuthParams to build AccountAuthService. The method getAuthParam() is used to returns AccountAuthService.
In the MainActivty we can call init() method from onCreate()
In the silentSignInByHwId method, calling getAuthParam() through Singleton class instance and get AccountAuthService (HUAWEI ID sign-in authorization service). Then call the silentSignIn API for silent sign-in. If the silent sign-in is successful, your app will directly obtain the ID token and verify it. If the silent sign-in fails, your app will call the getSignInIntent API to show the authorization or sign-in screen.
You can use the sign out method from any other activity. Here it calling getAuthParam() through Singleton class instance and get AccountAuthService. Then call the signout API for sign-out