Skip to main content

Lifecycle

Normal Launch Life Cycle#

1. SDK Initialization

To initialize the Photos SDK, call the following method:

PhotoManager.initInstance (...)

At that time, all internal SDK components are created. This method is usually called from Application.onCreate ()

2. Preparation for work

To prepare SDK for work, use the following method:

PhotoManager.prepareToWork (...)

During preparation for work, the following components appear in the application:

  • Base backend URL
  • User Auth-token
  • User Profile ID

As a rule, this data is available in the application after user authorization.

3. Startup

The autoupload of images to the cloud starts automatically when the following conditions are met:

  • The gallery was read from the backend (see PhotoManager.timline.reloadBackend ()). This method can be called after the method PhotoManager.prepareToWork once the user is authorized.
  • The local gallery was read (see PhotoManager.timeline.reloadLocal ()). This method can be called after the methodPhotoManager.prepareToWork (...) if the application has the READ_EXTERNAL_STORAGE permission.

4. End of the session

At the end of user session, when the application logs out the current user, you must call:

PhotoManager.handleLogout ()

At the next login, you will need to call PhotoManager.prepareToWork (...) again.

Background Launch Life Cycle#

The SDK contains a worker that runs periodically through the WorkManager. It is done so in order for the application to be able to upload photos to the cloud, even if the user does not start the application in the usual way.

The background worker reads the backend gallery and the local gallery, then autoupload starts automatically.

Since the application runs in the background without a UI, in order to ensure that the worker is operational, it is necessary to call the following methods before launching the worker, for example in Application.onCreate ().:

PhotoManager.initInstance(...)PhotoManager.prepareToWork(...)

The method PhotoManager.prepareToWork(...) is called if the user was previously authorized in the application and his token and profileId are stored in the application’s preferences.

In this case, the application is able to upload photos to the cloud without activating the UI.

Services and Threads#

While performing an autoupload, the SDK displays an ongoing notification by using the service and the methods startForeground (), stopForeground (). This is done in order to show the system that the application is performing an important operation and does not need to be completed.

All network operations and requests to the database are performed in the background threads.

The SDK uploads data to the cloud in several threads. To perform this operation, the Runnable workers are created and ThreadPoolExecutor is used.

The API Library functions can initiate the background operation. In such a case, the thread is switched by means of RxJava.

Logout#

TBD