4

I've started a project using AwsAppsync.

The app is going to be offline first. And we want to offer the option to sync in the cloud as an extra option later if the customer wants it. So, I configured my project like this:

In build.gradle added the following:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.6.2'
        classpath 'com.amplifyframework:amplify-tools-gradle-plugin:0.2.1'
    }
}

apply plugin: 'com.amplifyframework.amplifytools'

And added those dependencies:

implementation 'com.amplifyframework:core:0.10.0'
implementation 'com.amplifyframework:aws-api:0.10.0' // If using cloud sync
implementation 'com.amplifyframework:aws-datastore:0.10.0'

And then using the Amplify CLI:

copy Generate models at any time by executing this Amplify CLI command:

amplify codegen models

After this in the onCreate of the activity:

ModelProvider modelProvider = AmplifyModelProvider.getInstance();
Amplify.addPlugin(AWSDataStorePlugin.forModels(modelProvider));
Amplify.configure(getApplicationContext());

With this i can Query, update and delete the data.

Is this enough for a full offline experience?

Now, based on the documentation, to add online sync feature, I have to do the following:

Using the Amplify CLI:

amplify push

This will create the amplifyconfiguration.json with the sync configuration.

Now, this information seems to be set in build time. So, how can I enable/disable this feature to be used just when I need it? The documentation mention the following:

ModelProvider modelProvider = AmplifyModelProvider.getInstance();
Amplify.addPlugin(AWSDataStorePlugin.forModels(modelProvider));
Amplify.addPlugin(new AWSApiPlugin()); // If using remote model synchronization
Amplify.configure(getApplicationContext());

So, would be adding that "new AWSApiPlugin()" the only thing I need to do to enable/disable this feature? Thanks!

Any tutorial/book good enough to explain this? I've read several documentation(including the official) and I wasn't able to find something about this particular case. It is always with online sync from the get go.

Mariano L
  • 1,809
  • 4
  • 29
  • 51

1 Answers1

-2

From a high level, yes this is fairly accurate. DataStore doesn't require a backend it will just work as a local DB of sorts that you can use for offline including queries. When you add in a backend with amplify push (this deploys an AppSync API backed by DynamoDB) and connect it with AWSApiPlugin it will begin syncing. The best tutorial is in the docs: https://docs.amplify.aws

Richard
  • 1,750
  • 11
  • 11