【发布时间】:2010-11-15 12:34:56
【问题描述】:
我正在尝试向http://code.google.com/p/iosched/source/checkout 学习一些东西。我想看看他们是如何实现他们在 I/O 上谈论的 UI 模式的。
在 HomeActivity 中,他们使用此代码来启动 NotesActivity:
/* Launch list of notes user has taken*/
public void onNotesClick(View v) {
startActivity(new Intent(Intent.ACTION_VIEW, Notes.CONTENT_URI));
}
Notes 类在 ScheduleContract 类中,它看起来像:
public static class Notes implements NotesColumns, BaseColumns {
public static final Uri CONTENT_URI =
BASE_CONTENT_URI.buildUpon().appendPath(PATH_NOTES).build();
public static final Uri CONTENT_EXPORT_URI =
CONTENT_URI.buildUpon().appendPath(PATH_EXPORT).build();
/** {@link Sessions#SESSION_ID} that this note references. */
public static final String SESSION_ID = "session_id";
/** Default "ORDER BY" clause. */
public static final String DEFAULT_SORT = NotesColumns.NOTE_TIME + " DESC";
public static final String CONTENT_TYPE =
"vnd.android.cursor.dir/vnd.iosched.note";
public static final String CONTENT_ITEM_TYPE =
"vnd.android.cursor.item/vnd.iosched.note";
public static Uri buildNoteUri(long noteId) {
return ContentUris.withAppendedId(CONTENT_URI, noteId);
}
public static long getNoteId(Uri uri) {
return ContentUris.parseId(uri);
}
}
我看不到这段代码到底做了什么,以及它如何最终启动 NotesActivity 并加载了笔记。我也不明白 URI 如何以及什么用作 new 中的第二个参数:
意图(Intent.ACTION_VIEW,Notes.CONTENT_URI)。
我在谷歌上搜索了解释,但没有找到一个简单的例子。我猜想 Notes 类用于指向和格式化数据(便笺),然后以某种方式启动 NotesActivity,但不明白具体是如何。
【问题讨论】:
标签: android android-intent android-layout