Class ManagedGroundSdk


  • public final class ManagedGroundSdk
    extends GroundSdk
    An GroundSdk session automatically managed according to an android Activity lifecycle.

    This class allows the application to retrieve a GroundSdk session whose lifecycle is is automatically managed in correlation with a given Activity's own lifecycle.This is the recommended way to use GroundSdk API in an android Activity.

    The application should obtain such a session in the activity onCreate method. None of the session's lifecycle management methods, as described in GroundSdk documentation, need to be called.

    • The session is automatically retained and restored upon configuration changes.
    • The session is resumed when the activity calls through super.onStart() method (by default, but the application may chose to have it resumed in when the activity calls through super.onResume() method instead).
    • The session is suspended when the activity calls through super.onStop() method (by default, but the application may chose to have it suspended in when the activity calls through super.onPause() method instead).
    • The session is automatically closed when the activity calls through super.onDestroy(). The application MUST NOT use the session past this point.

    For example:

      public class MyManagedGroundSdkActivity extends Activity {
          private ManagedGroundSdk mGroundSdk;
    
         @Override
          public void onCreate(@Nullable Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              mGroundSdk = ManagedGroundSdk.obtainSession(this);
          }
    
         @Override
          public void onDestroy() {
              super.onDestroy();
              // mGroundSdk MUST NOT be used anymore past this point
          }
      }
     
    • Method Detail

      • obtainSession

        @NonNull
        public static ManagedGroundSdk obtainSession​(@NonNull
                                                     Activity activity,
                                                     @NonNull
                                                     ManagedGroundSdk.ObserverBehavior observerBehavior)
        Obtains a GroundSdk session automatically managed according to the provided activity's lifecycle.

        All observers registered through this session are resumed according to the provided observer behaviour.

        Parameters:
        activity - the activity whose lifecycle will control the session's own lifecycle
        observerBehavior - observer behaviour this session must comply to
        Returns:
        a GroundSdk session, automatically managed according to the given activity's lifecycle
      • obtainSession

        @NonNull
        public static ManagedGroundSdk obtainSession​(@NonNull
                                                     Activity activity)
        Obtains a GroundSdk session automatically managed according to the provided activity's lifecycle.

        All observers registered through this session are resumed in activity onStart() and suspended in activity onStop().
        Use obtainSession(Activity, ObserverBehavior) to customize this behavior if unsuitable to the application needs.

        Parameters:
        activity - the activity whose lifecycle will control the session's own lifecycle
        Returns:
        a GroundSdk session, automatically managed according to the given activity's lifecycle
        See Also:
        obtainSession(Activity, ObserverBehavior)