糖ORM很慢

时间:2016-08-20 12:46:39

标签: android android-recyclerview sugarorm

我有一个活动,其中有五个recyclerviews。 每个recyclerviews都有从Web服务加载的数据。

我使用糖orm来保存和检索数据。

 JSONObject latestRingtoneTenJSONObject = dialogue.getJSONObject(i);
 String albumId = latestRingtoneTenJSONObject.getString("album_id");
 String title = latestRingtoneTenJSONObject.getString("album_name");
 String albumName = latestRingtoneTenJSONObject.getString("total_songs");
 String imgUrl = latestRingtoneTenJSONObject.getString("img_url");
 Log.d("Note", "saving");
 Dialog kbAlbums = new Dialog( albumId, title , albumName,imgUrl);
 SugarRecord.saveInTx(kbAlbums);

问题是我得到以下警告,

  

应用程序可能在其主线程上做了太多工作。它会冻结我的应用

使用ui线程通过

更新回收站视图
MainActivity.act.runOnUiThread(new Runnable() {
                                public void run(){
                                    loadRecyclerView();
                                }
                            });

1 个答案:

答案 0 :(得分:1)

UI主题主线程。

您的代码的其他部分更有可能导致UI锁定,使用调试器来分析哪些部分需要更长时间。它可能是依赖于网络连接的任何东西,在这种情况下是loadRecyclerView();

考虑在新线程上从Web服务进行实际加载,然后仅在UI线程上进行实际视图更新,以提高性能。

相关问题