2017-07-29 69 views
0

让的地步的时候,这是我的代码:应用程序冻结将蔚蓝的后端表查询

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)上调试它,有人可以告诉我为什么会发生这种情况吗?即时通讯只是在一个月内学习Android。

UPDATE

这是最后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

您运行查询在主THEAD,负责UI更新(很长一段时间,换句话说操作)前。你需要使用AsyncTask,Loaders或简单地创建一个新的Thread实现来启动另一个线程。