Azure 连接成功,我在执行 CRUD 时得到正确的 JSON 结果,但没有响应,没有错误消息并停止工作
Azure connect successfully , I get correct JSON result when doing CRUD but then no Response , no Error Message And stop Working
我正在使用 Azure 移动服务开发 Android 应用程序 ,
我设置连接成功,
并确保 对后端的操作 将发送 正确 JSON 返回 .
但是当我打电话给
myUserTable.execute().get();
首先,我在日志中收到来自 ServiceFilter
的响应,其中内容 正确 JSON
但之后它停止工作,没有任何错误消息和异常 ...
它只是停止进一步工作...
请看下面我的代码:
对于CRUD操作函数:
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);
}
原来达不到Log.d("myLog","User id : "+us.size());
启动Azure设置的功能
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);
}
查询操作
public List<User> loadUserFromTable() throws ExecutionException, InterruptedException, MobileServiceException {
return mUserManager.execute().get();
}
这里是我们数据库中的所有表:
详细日志:
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":"水球潘管理員"}]
我已经解决了我的问题,
重点是,对MobileServiceTable的操作
必须 运行 在 非 UI 线程
所以这意味着
public List<User> loadUserFromTable() throws ExecutionException, InterruptedException, MobileServiceException {
return mUserManager.execute().get();
}
错了,我应该创建另一个线程来完成请求。
我正在使用 Azure 移动服务开发 Android 应用程序 ,
我设置连接成功,
并确保 对后端的操作 将发送 正确 JSON 返回 .
但是当我打电话给
myUserTable.execute().get();
首先,我在日志中收到来自 ServiceFilter
的响应,其中内容 正确 JSON但之后它停止工作,没有任何错误消息和异常 ...
它只是停止进一步工作...
请看下面我的代码:
对于CRUD操作函数:
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);
}
原来达不到Log.d("myLog","User id : "+us.size());
启动Azure设置的功能
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);
}
查询操作
public List<User> loadUserFromTable() throws ExecutionException, InterruptedException, MobileServiceException {
return mUserManager.execute().get();
}
这里是我们数据库中的所有表:
详细日志:
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":"水球潘管理員"}]
我已经解决了我的问题, 重点是,对MobileServiceTable的操作 必须 运行 在 非 UI 线程
所以这意味着
public List<User> loadUserFromTable() throws ExecutionException, InterruptedException, MobileServiceException {
return mUserManager.execute().get();
}
错了,我应该创建另一个线程来完成请求。