Additional DataStore methods
Clear
To stop DataStore sync process and to clear local data from DataStore, use the clear
method:
Amplify.DataStore.clear( () -> Log.i("MyAmplifyApp", "DataStore cleared"), error -> Log.e("MyAmplifyApp", "Error clearing DataStore", error));
Amplify.DataStore.clear( { Log.i("MyAmplifyApp", "DataStore cleared") }, { Log.e("MyAmplifyApp", "Error clearing DataStore", it) })
try { Amplify.DataStore.clear() Log.i("MyAmplifyApp", "DataStore cleared")} catch (error: DataStoreException) { Log.e("MyAmplifyApp", "Error clearing DataStore", error)}
RxAmplify.DataStore.clear() .subscribe( () -> Log.i("MyAmplifyApp", "DataStore cleared"), error -> Log.e("MyAmplifyApp", "Error clearing DataStore", error) );}
Start
Synchronization starts automatically whenever you run any DataStore operation (query()
, save()
, delete()
, observe()
.) You can also explicitly begin the process with DataStore.start()
:
Amplify.DataStore.start( () -> Log.i("MyAmplifyApp", "DataStore started"), error -> Log.e("MyAmplifyApp", "Error starting DataStore", error));
Amplify.DataStore.start( { Log.i("MyAmplifyApp", "DataStore started") }, { Log.e("MyAmplifyApp", "Error starting DataStore", it) })
try { Amplify.DataStore.start() Log.i("MyAmplifyApp", "DataStore started") } catch (error: DataStoreException) { Log.e("MyAmplifyApp", "Error starting DataStore", error)}
RxAmplify.DataStore.start() .subscribe( () -> Log.i("MyAmplifyApp", "DataStore started"), error -> Log.e("MyAmplifyApp", "Error starting DataStore", error) );}
Stop
To stop the DataStore sync process, you can use DataStore.stop()
. This will close the real time subscription connection when your app is no longer interested in updates. You will typically call DataStore.stop()
just before your application is closed. You can also force your DataStore sync expressions to be re-evaluated at runtime by calling stop()
followed by start()
.
Amplify.DataStore.stop( () -> Log.i("MyAmplifyApp", "DataStore stopped"), error -> Log.e("MyAmplifyApp", "Error stopping DataStore", error));
Amplify.DataStore.stop( { Log.i("MyAmplifyApp", "DataStore stopped") }, { Log.e("MyAmplifyApp", "Error stopping DataStore", it) })
try { Amplify.DataStore.stop() Log.i("MyAmplifyApp", "DataStore stopped")} catch (error: DataStoreException) { Log.e("MyAmplifyApp", "Error stopping DataStore", error)}
RxAmplify.DataStore.stop() .subscribe( () -> Log.i("MyAmplifyApp", "DataStore stopped"), error -> Log.e("MyAmplifyApp", "Error stopping DataStore", error) );}