Skip to content

Android SDK Creating the Collector

Raluca Pettinger edited this page Oct 27, 2017 · 1 revision

The Device Collector can be created at any time before the checkout/transaction request call is made. It’s recommended that the collector be created in a way that you can track its state when your application changes. The developer should keep a "reference" to the Collector once the process as started until it is completed (in either Success or Error). The application does not need to wait on the process to continue checkout.

You can create the DeviceCollector at any time, but you can wait to create it until it is needed. However, the DeviceCollector object should be created at a level in the application that does not destroy the object before completion (i.e. a member variable in the Activity or Application level, and not a local variable or in a subclass not kept at the member level).

Prior to collect() being called, the DeviceCollector can safely be destroyed and recreated without concern. Once collect() has been called, you should keep track of the DeviceCollector instance until the process completes in Success or Error, or your application finishes. You do not need to wait on this process to continue the user’s experience, but you do not want multiple instances of this library running for the same transaction.

See the Reference Implementation for code examples on both Fragment and non-Fragment style implementations. When the collector is actively running it runs in the background as an android.os.AsyncTask

(http://developer.android.com/reference/android/os/AsyncTask.html).

If your application handles destruction and recreation states while active (which most do) you will need to keep track of the Device Collector throughout those states. (i.e. storing the handles to the DeviceCollector and your class that implements the DeviceCollector.StatusListener)

For example, if your application supports configuration changes such as changing orientations (Landscape to portrait) the Android OS destroys and recreates the app unless you specifically override that behavior. If it is not overridden then the OS uses the State Bundles and onRetainNonConfigurationInstance() methods to handle recreation of the application. If your collector is running you should keep a reference to it during this process. For more information on the Android lifecycle, especially configuration changes, see their documentation here:

http://developer.android.com/reference/android/app/Activity.html#ConfigurationChanges