Reputation: 801
I am using Azure Mobile service developing Android application ,
I set the connection up successfully ,
and make sure that the Action to Backend will send Correct JSON back.
But When I call
myUserTable.execute().get();
first , I get a response in my log which contents correct JSON from ServiceFilter
but after then it stop working without any Error Message and Exception ...
it just stop further working ...
please see my codes below :
for the CRUD operation function :
private void initiate() {
AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>(){
@Override
protected Void doInBackground(Void... params) {
try {
runOnUiThread(new Runnable() {
@Override
public void run() {
try{
Link_Azure azure = null;
Log.d("myLog","Start Binding database");
azure = Link_Azure.bindWithMainActivity(MainActivity.this);
List<User> us= azure.loadUserFromTable();
Log.d("myLog","User id : "+us.size());
}catch(MalformedURLException | MobileServiceException | InterruptedException | ExecutionException err){
err.printStackTrace();
}
}
});
} catch (final Exception e) {
e.printStackTrace();
}
return null;
}
};
runAsyncTask(task);
}
It turns out not reach Log.d("myLog","User id : "+us.size());
Function for initiate Azure Setting
public static Link_Azure bindWithMainActivity(Context main) throws MalformedURLException {
if (azureInstance == null)
azureInstance = new Link_Azure(main);
return azureInstance;
}
private Link_Azure(Context main) throws MalformedURLException {
this.context = main;
mClient = new MobileServiceClient(LINK,context).withFilter(new ProgressFilter());
mClient.setAndroidHttpClientFactory(new OkHttpClientFactory() {
@Override
public OkHttpClient createOkHttpClient() {
OkHttpClient client = new OkHttpClient();
client.setReadTimeout(20, TimeUnit.SECONDS);
client.setWriteTimeout(20, TimeUnit.SECONDS);
return client;
}
});
initiateTables();
}
private void initiateTables(){
mUserManager = mClient.getTable("User",User.class);
mProduct = mClient.getTable("Product",ProductImp.class);
mMail = mClient.getTable("Mail",Mail.class);
mLockerImp = mClient.getTable("Locker",LockerImp.class);
}
for Query operation
public List<User> loadUserFromTable() throws ExecutionException, InterruptedException, MobileServiceException {
return mUserManager.execute().get();
}
And here are all Tables in our Database :
verbose Log:
03-08 07:25:46.467 9662-9662/com.example.androidwork.foodsharing W/art: Verification of void com.microsoft.windowsazure.mobileservices.table.sync.MobileServiceSyncContext.processOperation(com.microsoft.windowsazure.mobileservices.table.sync.operations.TableOperation, com.google.gson.JsonObject) took 218.338ms
03-08 07:25:46.542 9662-9756/com.example.androidwork.foodsharing W/ResourcesManager: Asset path '/system/framework/com.android.media.remotedisplay.jar' does not exist or contains no resources.
03-08 07:25:46.542 9662-9756/com.example.androidwork.foodsharing W/ResourcesManager: Asset path '/system/framework/com.android.location.provider.jar' does not exist or contains no resources.
03-08 07:25:47.227 9662-9759/com.example.androidwork.foodsharing D/myLog: [{"deleted":false,"updatedAt":"2017-03-06T15:13:47.927Z","createdAt":"2017-03-05T10:52:24.031Z","version":"AAAAAAAAC78=","id":"32C63DBF-F531-4ED9-ABF2-D83919C5F7E7","password":"123","account":"1235","email":null,"phone":null,"live":null,"age":15,"name":"水球潘管理員"}]
Upvotes: 0
Views: 57
Reputation: 801
I have solved my problem , the point is , the operation on MobileServiceTable must run on the Non-UI thread
So that means
public List<User> loadUserFromTable() throws ExecutionException, InterruptedException, MobileServiceException {
return mUserManager.execute().get();
}
is wrong , I should create another Thread to do the request.
Upvotes: 0