Search code examples
google-app-enginecloudrpcgwt-rpc

Write multiple times(Enities) using RPC proxyclass in Google App-Engine from Android


I am using App Engine Connected Android Plugin support and customized the sample project shown in Google I/O. Ran it successfully. I wrote some Tasks from Android device to cloud succesffully using the code.

CloudTasksRequestFactory factory = (CloudTasksRequestFactory) Util
                                        .getRequestFactory(CloudTasksActivity.this,
                                                CloudTasksRequestFactory.class);
                                TaskRequest request = factory.taskRequest();

                            TaskProxy task = request.create(TaskProxy.class);
                            task.setName(taskName);
                            task.setNote(taskDetails);
                            task.setDueDate(dueDate);

                            request.updateTask(task).fire();

This works well and I have tested.

What I am trying to now is I have an array String[][] addArrayServer and want to write all the its elements to the server. The approach I am using is:

NoteSyncDemoRequestFactory factory = Util.getRequestFactory(activity,NoteSyncDemoRequestFactory.class);
        NoteSyncDemoRequest request = factory.taskRequest();

        TaskProxy task;
        for(int ik=0;ik<addArrayServer.length;ik++) {
            task = request.create(TaskProxy.class);



            Log.d(TAG,"inside uploading task:"+ik+":"+addArrayServer[ik][1]);
            task.setTitle(addArrayServer[ik][1]);
            task.setNote(addArrayServer[ik][2]);
            task.setCreatedDate(addArrayServer[ik][3]);


            // made one task

            request.updateTask(task).fire();
        }

One task is uploaded for sure, the first element of the array. But hangs when making a new instance of task. I am pretty new to Google-Appengine. Whats the right way to call RPC, to upload multiple entities really fast??

Thanks.


Solution

  • Well answer to this queston is that request.fire() can be called only once for an request object but I was calling it every time in the loop. So it would update only once. Simple solution is to call fire() outside the loop.

    NoteSyncDemoRequestFactory factory = Util.getRequestFactory(activity,NoteSyncDemoRequestFactory.class); NoteSyncDemoRequest request = factory.taskRequest();

        TaskProxy task;
        for(int ik=0;ik<addArrayServer.length;ik++) {
            task = request.create(TaskProxy.class);
    
    
    
            Log.d(TAG,"inside uploading task:"+ik+":"+addArrayServer[ik][1]);
            task.setTitle(addArrayServer[ik][1]);
            task.setNote(addArrayServer[ik][2]);
            task.setCreatedDate(addArrayServer[ik][3]);
    
    
            // made one task
    
            request.updateTask(task);
        }
    request.fire(); //call fire only once after all the actions are done...
    

    For more info check out this question.. GWT RequestFactory and multiple requests