你好,游客 登录 注册 搜索
背景:
阅读新闻

Android短彩信幻灯片异步加载机制

[日期:2013-03-24] 来源:Linux社区  作者:hailushijie [字体:大 中 小]

在我们每次删除会话时,会清空所有缓存。

public static void startDelete(ConversationQueryHandler handler, int token, boolean deleteAll,
            long threadId) {
        synchronized(sDeletingThreadsLock) {
            if (sDeletingThreads) {
                Log.e(TAG, "startDeleteAll already in the middle of a delete", new Exception());
            }
            sDeletingThreads = true;
            Uri uri = ContentUris.withAppendedId(Threads.CONTENT_URI, threadId);
            String selection = deleteAll ? null : "locked=0";

            MmsApp.getApplication().getPduLoaderManager().clear();//这里会将缓存的信息全部清空,下次进入短彩信,重新更新缓存。

            // HACK: the keys to the thumbnail cache are the part uris, such as mms/part/3
            // Because the part table doesn't have auto-increment ids, the part ids are reused
            // when a message or thread is deleted. For now, we're clearing the whole thumbnail
            // cache so we don't retrieve stale images when part ids are reused. This will be
            // fixed in the next release in the mms provider.
            MmsApp.getApplication().getThumbnailManager().clear();

            handler.setDeleteToken(token);
            handler.startDelete(token, new Long(threadId), uri, selection, null);
        }
    }

当删除单条信息时,会先清空这条信息对应的缓存,然后在删除。这个顺序很重要,如果先删除信息,在清空缓存信息,那么短彩信可能会引发同步错误。

private class DeleteMessageListener implements OnClickListener {
        private final MessageItem mMessageItem;

        public DeleteMessageListener(MessageItem messageItem) {
            mMessageItem = messageItem;
        }

        @Override
        public void onClick(DialogInterface dialog, int whichButton) {
            dialog.dismiss();

            new AsyncTask<Void, Void, Void>() {
                protected Void doInBackground(Void... none) {
                    if (mMessageItem.isMms()) {
                        WorkingMessage.removeThumbnailsFromCache(mMessageItem.getSlideshow());

                        MmsApp.getApplication().getPduLoaderManager()
                            .removePdu(mMessageItem.mMessageUri);
                        // Delete the message *after* we've removed the thumbnails because we
                        // need the pdu and slideshow for removeThumbnailsFromCache to work.
                    }
                    mBackgroundQueryHandler.startDelete(DELETE_MESSAGE_TOKEN,
                            null, mMessageItem.mMessageUri,
                            mMessageItem.mLocked ? null : "locked=0", null);
                    return null;
                }
            }.execute();
        }
    }

以上就是幻灯片异步加载的一个大体流程。

相关阅读:Android短彩信附件机制 http://www.linuxidc.com/Linux/2013-03/81529.htm

更多Android相关信息见Android 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=11

linux
相关资讯       Android幻灯片  Android异步加载 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款