Class MobileService
-
- All Implemented Interfaces:
public abstract class MobileServiceRepresents the base class for all mobile services, for example, UserService, etc. Each service represents a feature that the mobile app wants to use. To use a service, create an instance of that service, then feed to SDKInitializer to initialize it, then later client code can get the instance from SDKInitializer.
-
-
Field Summary
Fields Modifier and Type Field Description private Applicationapplicationprivate StringapiKeyprivate SharedPreferencessdkSharedPreferences
-
Constructor Summary
Constructors Constructor Description MobileService()
-
Method Summary
Modifier and Type Method Description final ApplicationgetApplication()The application instance final UnitsetApplication(Application value)The application instance final StringgetApiKey()The api key that can connect to mobile server final UnitsetApiKey(String value)The api key that can connect to mobile server final SharedPreferencesgetSdkSharedPreferences()SDK shared preference final UnitsetSdkSharedPreferences(SharedPreferences value)SDK shared preference UnitenableNetworkPolicy(NetworkPolicy policy)Enable and set network policy for mobile service. final UnitinitSharedPreference()For child mobile service classes, if shared preference is used, call this in the init function. final NetworkTypegetNetworkType(String componentName)Help mobile services using worker convert NetworkPolicyeffectiveNetworkPolicy to NetworkType final BooleanisApplicationInitialized()Check whether application instance is initialized. Unitinit(Application application, String apiKey)Initializes the mobile service Unitreset()Resets the mobile service to the state that just initialized. UnitonStateChange(ApplicationState state)Notified when application state changes. final BooleanprerequisiteReady()Most service can only be used when SettingsParameters and 'httpClient' are ready final <T extends Any> UnitobserveWorker(Context context, WorkRequest request, ServiceListener<T> listener, String tag, Function1<WorkInfo, ServiceResult<T>> getServiceResult)Observers a worker request from the main thread, and report the result to the given listener. BooleanmayStartNewProcess()Indicates whether this service might start a process. -
-
Method Detail
-
getApplication
final Application getApplication()
The application instance
-
setApplication
final Unit setApplication(Application value)
The application instance
-
getApiKey
final String getApiKey()
The api key that can connect to mobile server
-
setApiKey
final Unit setApiKey(String value)
The api key that can connect to mobile server
-
getSdkSharedPreferences
final SharedPreferences getSdkSharedPreferences()
SDK shared preference
-
setSdkSharedPreferences
final Unit setSdkSharedPreferences(SharedPreferences value)
SDK shared preference
-
enableNetworkPolicy
Unit enableNetworkPolicy(NetworkPolicy policy)
Enable and set network policy for mobile service.
-
initSharedPreference
final Unit initSharedPreference()
For child mobile service classes, if shared preference is used, call this in the init function.
-
getNetworkType
final NetworkType getNetworkType(String componentName)
Help mobile services using worker convert NetworkPolicyeffectiveNetworkPolicy to NetworkType
- Parameters:
componentName- The component listed in NetworkPolicy: analytics, clientResource, offlineOData, logs- Returns:
networkType converted from effectiveNetworkPolicy if it is set, otherwise NetworkType.NOT_ROAMING
-
isApplicationInitialized
final Boolean isApplicationInitialized()
Check whether application instance is initialized.
-
init
Unit init(Application application, String apiKey)
Initializes the mobile service
-
reset
Unit reset()
Resets the mobile service to the state that just initialized.
-
onStateChange
Unit onStateChange(ApplicationState state)
Notified when application state changes. This function will be called on Main thread.
-
prerequisiteReady
final Boolean prerequisiteReady()
Most service can only be used when SettingsParameters and 'httpClient' are ready
-
observeWorker
final <T extends Any> Unit observeWorker(Context context, WorkRequest request, ServiceListener<T> listener, String tag, Function1<WorkInfo, ServiceResult<T>> getServiceResult)
Observers a worker request from the main thread, and report the result to the given listener. getServiceResult takes the observed WorkInfo as input to return the ServiceResult
- Parameters:
context- The application contextrequest- The worker requestlistener- The listener to observe the worker resulttag- The tag of the work request, if present, the previous request with this tag will be cancelled first.getServiceResult- The callback for the client code to return the service result.
-
mayStartNewProcess
Boolean mayStartNewProcess()
Indicates whether this service might start a process. For example, Baidu push service has a service to be started in another process, thus we need to initialize the sqlite libraries before starting all the services.
-
-
-
-