0

I am creating an Android application that needs to store/retrieve data in DynamoDB. I created a DynamoDB table called "Schedules" and I created a Schedules class perthis tutorial. However, this tutorial is weirdly missing where/how to place authentication code and Object mapper code.

I used Amazon Cognito, created an identity pool, and got the resulting sample code, as referenced here under the Providing AWS Credentials header, #4. Where is this code supposed to go? In its own class? In the activity where I'm displaying/creating the data from the table? If so, where (onCreate(), its own method, etc?). Thanks in advance for your help!

Bob Kinney
  • 8,870
  • 1
  • 27
  • 35
L. Becker
  • 59
  • 1
  • 9

1 Answers1

1

Thanks a lot for pointing this out. We'll work to get the docs updated.

The credentials provider is passed to the DynamoDB client, which is in turn passed to the mapper.

AmazonDynamoDBClient ddb = new AmazonDynamoDBClient(credentialsProvider);
DynamoDBMapper mapper = new DynamoDBMapper(ddb);

Where this code goes will depend on your application, but it is a good practice to try to keep a single reference to the mapper and client, so in onCreate() or in a separate shared class is probably most appropriate.

Bob Kinney
  • 8,870
  • 1
  • 27
  • 35
  • In the sample Cognito code, it has the line: myActivity.getContext(). I added this code to an activity in the onCreate() method, but this.getContext() does not work, because getContext() is not a method for Activity. There is getBaseContext() and getApplicationContext(). How do I make this line work? – L. Becker Nov 12 '14 at 20:37
  • Which sample code are you looking at, and which line? As [this question](http://stackoverflow.com/questions/10641144/difference-between-getcontext-getapplicationcontext-getbasecontext-and) answers, each has different use cases, but it would help me if I saw what you were looking at. – Jeff Bailey Nov 17 '14 at 22:55