告诉我们,这是我的代码:
private MobileServiceClient mClient;
private MobileServiceTable<tblClass> mTable;
@Override
protected void onCreate(Bundle savedInstanceState) {
getSupportActionBar().hide();
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if( getIntent().getBooleanExtra("Exit me", false)){
finish();
return;
}
try {
mClient = new MobileServiceClient(
"https://applink.azurewebsites.net",
this
);
mTable = mClient.getTable(tblClass.class);
// when this line added, the app freezes, with no information on the logcat
List<tblClass> results = mTable
.execute()
.get();
// end of the line
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (MobileServiceException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
}
我已经尝试使用此
将返回数据添加到列表中Toast.makeText(this, results.indexOf(0), Toast.LENGTH_SHORT).show();
结果仍然相同,应用冻结了 我已经尝试在许多Android版本(从4.4到7.0)上调试它,有人可以告诉我为什么会发生这种情况吗?我只是在一个月内学习安卓。
更新
这是应用冻结之前的最后一次logCat
07-30 01:50:30.168 24014-24014/id.co.mandiri.e_absenmandiri I/InstantRun: starting instant run server: is main process
07-30 01:50:30.332 24014-24014/id.co.mandiri.e_absenmandiri W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
07-30 01:50:30.604 24014-24027/id.co.mandiri.e_absenmandiri I/art: Background sticky concurrent mark sweep GC freed 1973(388KB) AllocSpace objects, 0(0B) LOS objects, 20% free, 1579KB/1983KB, paused 5.293ms total 20.441ms
答案 0 :(得分:0)
你在主要的thead中运行你的查询(换句话说,长时间操作),负责UI更新。您需要使用AsyncTask,Loaders或仅创建一个新的Thread实现来启动另一个线程。