Class MobileService

  • All Implemented Interfaces:

    
    public abstract class MobileService
    
                        

    Represents 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.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Constructor Summary

      Constructors 
      Constructor Description
      MobileService()
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      final Application getApplication() The application instance
      final Unit setApplication(Application value) The application instance
      final String getApiKey() The api key that can connect to mobile server
      final Unit setApiKey(String value) The api key that can connect to mobile server
      final SharedPreferences getSdkSharedPreferences() SDK shared preference
      final Unit setSdkSharedPreferences(SharedPreferences value) SDK shared preference
      Unit enableNetworkPolicy(NetworkPolicy policy) Enable and set network policy for mobile service.
      final Unit initSharedPreference() For child mobile service classes, if shared preference is used, call this in the init function.
      final NetworkType getNetworkType(String componentName) Help mobile services using worker convert NetworkPolicyeffectiveNetworkPolicy to NetworkType
      final Boolean isApplicationInitialized() Check whether application instance is initialized.
      Unit init(Application application, String apiKey) Initializes the mobile service
      Unit reset() Resets the mobile service to the state that just initialized.
      Unit onStateChange(ApplicationState state) Notified when application state changes.
      final Boolean prerequisiteReady() Most service can only be used when SettingsParameters and 'httpClient' are ready
      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.
      Boolean mayStartNewProcess() Indicates whether this service might start a process.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • MobileService

        MobileService()
    • 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

      • 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

      • 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.

      • 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 context
        request - The worker request
        listener - The listener to observe the worker result
        tag - 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.