HotMovie

2016.10.21:

之前的更新都没有贴出来。接下来对应用还会有一些重构,每隔一阶段将更新工作总结一下贴上来,顺路学习下git的命令行操作。

Version:2.2

地址:https://github.com/yusband/HotMovie/tree/HotMovie2.2

New Features:

  • 新增了收藏功能,可以在详情页点击收藏,将电影海报缓存至手机存储卡,在主页面的显示模式中点击“我的收藏”即可获得收藏过电影的列表

遇到的坑:

  • 如何看到sqliteDatabase中存储的内容
  1. 使用adb shell工具,通过命令行进入 data/data/包名/databases 之后,出现opendir failed, Permission denied的错误提示
  2. 根据http://stackoverflow.com/questions/19194576/how-do-i-view-the-sqlite-database-on-an-android-device该链接下列出的方法并没有解决问题;采用真机测试(小米5s,api 23)
  3. 最终的解决办法是没有尝试root手机(小米root需要申请...),将程序在avm上运行,直接在DDMS下找到.db文件,在火狐浏览器的SQLite Manager中查看
  • UriMatcher无法识别Uri的bug
  1. private static final int MOVIE =100 ;
        private static final int MOVIE_ALL =200 ;
        private static final int MOVIE_CERTAIN =300 ;
        private OpenHelper mOpenHelper;
        static UriMatcher buildUriMatcher() {
    
            UriMatcher matcher=new UriMatcher(UriMatcher.NO_MATCH);
    
            final String authority=MovieContact.CONTENT_AUTHORITY;
            matcher.addURI(authority,MovieContact.PATH_MOVIE, MOVIE);
            matcher.addURI(authority,MovieContact.PATH_MOVIE+"/*",MOVIE_ALL);
            matcher.addURI(authority,"movie/#",MOVIE_CERTAIN);
    public int delete(Uri uri, String s, String[] strings) {
            final SQLiteDatabase db = mOpenHelper.getWritableDatabase();
            final int match = sUriMatcher.match(uri);
            int deleteRows=0;
    
            switch (match) {
                case MOVIE_CERTAIN: {
    
                   deleteRows=db.delete(MovieContact.MovieEntry.TABLE_NAME,s,strings);
                    if ( deleteRows<= 0 )
                        throw new android.database.SQLException("Failed to insert row into " + uri);
                    break;
                }
                case MOVIE_ALL: {
    
                    Log.i("movie_all","");
                }
                case  MOVIE:{
                    Log.i("movie","");
                }
                default:
                    throw new UnsupportedOperationException("Unknown uri: " + uri);
            }
            getContext().getContentResolver().notifyChange(uri, null);
            return deleteRows;
    }

    以上是继承自ContentProvider类中的UriMatcher和delete方法,运行会抛出 预定义的UnsupportedOperationException异常

  2. 参考http://stackoverflow.com/questions/5030094/problems-with-androids-urimatcher/15015687#15015687,uriMatcher的识别同定义时addUri的顺序有关:

应当避免在addUri时将*/# 与 */*放在相邻的两行,这里尽管在addUri中定义了如图所示的uri,当match时会因为CONTENT_URI/*在前,而且segment形式一致,会直接返回match CONTENT_URI/*的结果,会抛出异常。

当在初始化uriMatcher()的过程中,将CONTENT_URI/*和CONTENT_URI/#的顺序交换,便不会抛出异常;这也提醒在定义UriMatcher的过程中,需要注意顺序,格式可以参考官方文档:

sURIMatcher.addURI("contacts", "people", PEOPLE);
        sURIMatcher.addURI("contacts", "people/#", PEOPLE_ID);
        sURIMatcher.addURI("contacts", "people/#/phones", PEOPLE_PHONES);
        sURIMatcher.addURI("contacts", "people/#/phones/#", PEOPLE_PHONES_ID);
        sURIMatcher.addURI("contacts", "people/#/contact_methods", PEOPLE_CONTACTMETHODS);
        sURIMatcher.addURI("contacts", "people/#/contact_methods/#", PEOPLE_CONTACTMETHODS_ID);
        sURIMatcher.addURI("contacts", "deleted_people", DELETED_PEOPLE);
        sURIMatcher.addURI("contacts", "phones", PHONES);
        sURIMatcher.addURI("contacts", "phones/filter/*", PHONES_FILTER);
        sURIMatcher.addURI("contacts", "phones/#", PHONES_ID);
        sURIMatcher.addURI("contacts", "contact_methods", CONTACTMETHODS);
        sURIMatcher.addURI("contacts", "contact_methods/#", CONTACTMETHODS_ID);
        sURIMatcher.addURI("call_log", "calls", CALLS);
        sURIMatcher.addURI("call_log", "calls/filter/*", CALLS_FILTER);
        sURIMatcher.addURI("call_log", "calls/#", CALLS_ID);
时间: 2024-10-25 16:20:35

HotMovie的相关文章

AEAI WX微信扩展框架技术手册

1 概述 数通畅联微信公众号申请之后,由于要满足提供网站推广.功能演示.以及公司内部移动办公三方面的需求,所以把最初的订阅号更改为服务号,同时做了实名认证,这样就可以获取微信公众平台绝大部分接口,在完成数通畅联公众号相关功能过程中参考网上大量资料,期间封装AEAI WX微信扩展框架托管于开源中国社区http://git.oschina.net/agileai/aeaiwx. 在这里感谢特别柳峰对微信公众号知识的普及和推广,这是他博客链接http://blog.csdn.net/lyq8479,在