Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * A simple class for handling calls to Cloud Endpoints on background thread.
- * This way the UI thread will not get blocked.
- */
- public class NoteendpointAsyncTask extends AsyncTask<Note, Void, Void> {
- @Override
- protected Void doInBackground(Note... notes) {
- Noteendpoint.Builder endpointBuilder = new Noteendpoint.Builder(
- AndroidHttp.newCompatibleTransport(),
- new JacksonFactory(),
- new HttpRequestInitializer() {
- @Override
- public void initialize(HttpRequest arg0) throws IOException {}
- });
- Noteendpoint endpoint = CloudEndpointUtils.updateBuilder(endpointBuilder).build();
- for(Note note : notes) {
- try {
- // Make the call into Noteendpoint, requesting insertion of the given Note.
- endpoint.insertNote(note).execute();
- }
- catch (IOException e) {
- // Catching some exceptions
- }
- }
- return null;
- }
- }
- /*
- * The above class can then be used in someActivity.java like this
- */
- Note testNote = new Note();
- testNote.setDescription("One small note for me, one giant note for mankind");
- testNote.setId("someId");
- testNote.setEmailAddress("test@example.com");
- NoteendpointAsyncTask noteAsync = new NoteendpointAsyncTask();
- noteAsync.execute(testNote);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement