0
votes

I'm implementing Mobile Services for my Android App to connect to azure. I've run through the offline sync tutorial and that works fine.

I've now tried to implement the same method in my app with a different table and I get a Push Exception. Funny thing is that it still gets inserted into the online database. Anyone got a clue why this is happening?

As a test, I implemented the same class, tables, etc in the ToDoItem project without error.

Exception below

W/System.err: java.util.concurrent.ExecutionException: com.microsoft.windowsazure.mobileservices.table.sync.push.MobileServicePushFailedException
W/System.err:     at com.google.common.util.concurrent.AbstractFuture$Sync.getValue(AbstractFuture.java:299)
W/System.err:     at com.google.common.util.concurrent.AbstractFuture$Sync.get(AbstractFuture.java:286)
W/System.err:     at com.google.common.util.concurrent.AbstractFuture.get(AbstractFuture.java:116)
W/System.err:     at com.heathrow.ecms.DatabaseAccess$3.doInBackground(DatabaseAccess.java:2178)
W/System.err:     at com.heathrow.ecms.DatabaseAccess$3.doInBackground(DatabaseAccess.java:2173)
W/System.err:     at android.os.AsyncTask$2.call(AsyncTask.java:292)
W/System.err:     at java.util.concurrent.FutureTask.run(FutureTask.java:237)
W/System.err:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
W/System.err:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
W/System.err:     at java.lang.Thread.run(Thread.java:818)
W/System.err: Caused by: com.microsoft.windowsazure.mobileservices.table.sync.push.MobileServicePushFailedException
W/System.err:     at com.microsoft.windowsazure.mobileservices.table.sync.MobileServiceSyncContext.pushOperations(MobileServiceSyncContext.java:959)
W/System.err:     at com.microsoft.windowsazure.mobileservices.table.sync.MobileServiceSyncContext.consumePushSR(MobileServiceSyncContext.java:859)
W/System.err:     at com.microsoft.windowsazure.mobileservices.table.sync.MobileServiceSyncContext.access$1100(MobileServiceSyncContext.java:83)
W/System.err:     at com.microsoft.windowsazure.mobileservices.table.sync.MobileServiceSyncContext$PushSyncRequestConsumer.run(MobileServiceSyncContext.java:1120)

Code for sync is exactly the same as in the tutorial but with a different table, the error is on the push line.

private AsyncTask<Void, Void, Void> sync() {
    AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>(){
        @Override
        protected Void doInBackground(Void... params) {
            try {
                MobileServiceSyncContext syncContext = mClient.getSyncContext();
                syncContext.push().get();
                mtblAttachment.pull(null).get();
            } catch (final Exception e) {
                e.printStackTrace();
            }
            return null;
        }
    };
    return runAsyncTask(task);
}
1
Which tutorial are you referring to? And are you using version 24 or 25 of the api? - Mike
@Mike Sorry this tutorial here I'm using API 23. - SliderUK
Sorry don't know the specific answer but there's a post here on it stackoverflow.com/questions/35019417/… - maybe an authentication issue? - Mike
Ye i saw that question but in the ToDoItem tutorial I implemented my same class and tables and it works fine without issue. - SliderUK
Ok not sure what is going on, but the data is in azure but not locally, I've try to query and everything locally is null apart from the Id. I look on azure and the data is what it should be. How does that happen? I thought I add it locally then sync and it goes to azure therefore on both tables. Looks like the actual sync is thinking there's a conflict or something and removing the data locally? - SliderUK

1 Answers

2
votes

Ok after my last comment yesterday I've worked out the problem.

The SerializedName fields in your class must match (case sensitive) what you put in the initLocalDatabase. Even though this error did not show up in my test run on the ToDoItem app it showed up when I implemented it in my actual app.

So if you get the MobileServicePushFailedException please check that your SerializedName fields matches your local database field names. For some reason it does not affect the Azure database fields, that's why I saw my data go to Azure but not my local database. Best practice make all fields exactly the same (think I was being lazy at the time!).