一、android:stopWithTask 用于 <service> 可在 R.attr 中找到,有两个疑惑:

1、为啥在R.attr中找到?它里面不都是Resource的ID吗.

2、不知道这个标签对 service 有什么影响

二、LinearLayout 有一个 android:gravity 属性用于设置其内部 view 摆放方式,如 垂直居中、水平居中等

三、

TextUtils.isEmpty(mSearchString)
检查一个字符串是否为空,注意 TextUtils 工具类的使用

四、Java Exception 是不跨线程的, 有时间仔细研究下

  

五、 ContentUris 工具类有时间仔细看下文档/ Uri 有时间仔细看下文档/ UriBiulder/

六、View --> TextView --> EditView 这个文档要看

七、

SQLiteDatabase db = mOpenHelper.getReadableDatabase();Cursor c = qb.query(db, projection, selection, selectionArgs, null, null, mySortOrder);//Cursor ContentResolver Uri 之间的关系是什么c.setNotificationUri(getContext().getContentResolver(), uri);return c;
long rowId = db.insert(NOTES_TABLE_NAME, null, contentValues);if(rowId > 0) {Uri newUri = ContentUris.withAppendedId(NotePad.Notes.CONTENT_URI, rowId);        //这里的 ContentResolver.notifyChange(Uri,null)做了什么工作?        //和 Cursor.setNotificationUri()有什么关系        getContext().getContentResolver().notifyChange(newUri, null);return newUri;} else {// android.database.SQLExceptionthrow new SQLException("Failed to insert row into " + uri);}

在实现 ContentProvider 的query 时,一般都有下面几行代码:

SQLiteDatabase db = mOpenHelper.getReadableDatabase();Cursor c = qb.query(db, projection, selection, selectionArgs, null, null, mySortOrder);//这一行的代码的作用?c.setNotificationUri(getContext().getContentResolver(), uri);return c;
下面具体说下注释的那行的作用?
从字面上看 setNotificationUri, 即 Uri 有改变时对本 Cursor 发出通知.
查看 AbstractCursor.setNotificationUri 源代码如下:

public void setNotificationUri(ContentResolver cr, Uri notifyUri) {mContentResolver = cr;mNotifyUri = notifyUri;mSelfObserver = new SelfContentObserver(this);//cr.registerContentObserver(notifyUri, mSelfObserver)mContentResolver.registerContentObserver(mNotifyUri, true, mSelfObserver);}
这个方法的作用就是在 ContentResolver上注册一个 Observer,

当 ContentResolver.notifyChange 时将调用已经注册的 ContentObserver, 你可以通过调用 ContentResolver.registerContentObserver 明确的给 ContentReselover注册观察者,
在这里我们并没有明确的调用 registerContentReselover方法, 而是通过 Cursor.setNotificationUri 间接的注册了一个 ContentObserver.

这个间接注册的好处是什么呢?
间接注册时的 ContentObserver 是 AbstractCursor的一个内部类, 这个以内部类形式存在的 ContentObserver把 AbstractCursor关联进去.

总体上的过程为:

//这个 Cursor 会被 Context.getContentResolver().query() 返回Cursor c = SQLiteDatabase.query();// 在 ContentResolver上注册一个 ContentObserverc.setNotificationUri(ContentResolver,Uri)//如果ContentObserver参数为null, 则ContentResolver会通知上一步注册的ContentObservergetContentResolver().notifyChange(Uri,ContentObserver)//Abstract Cursor 源码中的 setNotificationUri方法下的new SelfContentObserver(this) //会获得ContentResolver发出的通知
SelfContentObserver会通知和其关联的Cursor(初始化SelfContentObserver时进行关联)
Cursor会调用 onChange 通知自己的 ContentObserver. 其中默认的 ContentObserver是 CursorAdapter
也就是说 Cursor 也有 ContentObserver, 而它的默认 ContentObserver是在这个时候设立的:

//在这个构造数内会设置 Cursor 的观察者为 CursorAdapter,具体可以查看源代码跟踪一下SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.notes_list_item,         c/* 指Cursor */, new String[]{NotePad.Notes.TITLE}, new int[]{R.id.text1});
另外Uri参数的用处没有搞太清楚,但总体上是:
content://com.example.notepad/notes/5 这种Uri也会引起 content://com.example.notepad/notes 这种Uri的改变

八、Menu下面的一个方法:

int addIntentOptions(int groupId, int itemId, int order, ComponentName caller, Intent[] specifics,Intent intent, int flags, MenuItem[] outSpecificItems);
这个方法中的第六个参数 intent, 一般Action为null, 并且设置Data为当前Activity相关的,同时包含Category为CATEGORY_ALTERNATIVE或CATEGORY_SECOND_ALTERNATIVE. (如果一个Activity的<intent-filter>声明为CATEGORY_ALTERNATIVE则这个Activity可以在另一个Activity的Options Menu中出现)

解释这个方法的几个参数含义:

groupId: 如果有多外intent-filter满足 intent,则会出现多个 MenuItem,这些MenuItem都属于这个 groupId

itemId:

order:

ComponentName: 此菜单属于的那个 Activity

specifics: 如果有多外intent-filter满足intent, 则specifics指定了它们的顺序

flags:

outSpecificItems: 对应 specifics的menuItem


九、public boolean onOptionsItemSelected(MenuItem item)

这个方法的返回值应该特别的注意, 如果返回true, 则系统不会再处理后续事情. 在一些情况下是不能返回 ture的, 如你在 onCreateOptionsMenu 方法中调用 Menu.addIntentOptions 方法生成菜单项, 当这个菜单项被点击时后续的处理应该由系统完成,如果你返回 true,那么系统就不再处理后续流程.


十、

TextView 属性:
android:ems 指TextView的宽可以容纳25个英文字符
android:autoText 使此TextView可以纠错

十一、

可以在 layout.xml 文件中这样使用你自己定义的组件

<view xmlns:android="http://schemas.android.com/apk/res/android"    class="com.example.android.notepad.NoteEditor$LinedEditText"    android:id="@+id/note"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:background="@android:color/transparent"    android:padding="5dip"    android:scrollbars="vertical"    android:fadingEdge="vertical"    android:gravity="top"    android:textSize="22sp"    android:capitalize="sentences"/>
当然也可以这样使用:

<com.example.android.notepad.NoteEditor$LinedEditText xmlns:android="http://schemas.android.com/apk/res/android"android:id="@+id/note"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:background="@android:color/transparent"    android:padding="5dip"    android:scrollbars="vertical"    android:fadingEdge="vertical"    android:gravity="top"    android:textSize="22sp"    android:capitalize="sentences"/>

更多相关文章

  1. 常用的Js调Android方法,以及Android原生传值给Js
  2. 集成第三方库到android程序方法
  3. Android——《Android第一行代码》中使用通知 方法,Android8.0系
  4. 在Android Stduio 中使用requestWindowFeature(Window.FEATURE_N
  5. Android禁止横竖屏和解决切换屏幕时重启Activity的方法
  6. Android官方DrawerLayout 抽屉式侧滑菜单-简单使用方法
  7. Android Emulator 模拟器使用方法
  8. Android心得4.3--SQLite数据库--execSQL()和rawQuery()方法
  9. Android学习系列(2)--App自动更新之通知栏下载

随机推荐

  1. Android处理异步耗时任务,AsyncTask使用教
  2. Android常用组件之四大天王
  3. 由浅入深研究Android(1)--开篇•序
  4. error: Error parsing XML: unbound pref
  5. Ubuntu下安装VirtualBox和Android(安卓)
  6. Google Map Android v2开发: 安装运行Goo
  7. 关于 android 加载 res 图片 out of memo
  8. 【视频】 安卓渗透课程收集整理
  9. Gradle 构建 android 应用常见问题解决指
  10. Intent机制详解