所以我试图理解 NotePad 示例中的所有代码,但我遇到了一些困难:
首先,如何判断我们的项目是从“X”文件开始的?像一个“索引”文件..?
(我想它是从 NoteList 页面开始的)在这个 NoteList 页面中,我们使用 getIntent() 获取当前 Intent ,然后从中获取数据:但是:
- 哪个 Activity 启动了笔记列表? (我认为没有,而且这个项目中的所有 Activity 都有这个 getIntent() 方法,那么在项目启动时是否有一个自动“发送”的 Intent ?)
- 我们将数据设置为新的 intent 变量,然后我们像这样将数据拉入游标:
getIntent().getData()
:它是通过“引用”还是类似的方式传递的那?这样使用新的 Intent 变量或 getIntent() 是一样的吗?
感谢您的帮助;-)
>
// Gets the intent that started this Activity.
Intent intent = getIntent();
// If there is no data associated with the Intent, sets the data to the default URI, which
// accesses a list of notes.
if (intent.getData() == null) {
intent.setData(NotePad.Notes.CONTENT_URI);
}
/*
* Sets the callback for context menu activation for the ListView. The listener is set
* to be this Activity. The effect is that context menus are enabled for items in the
* ListView, and the context menu is handled by a method in NotesList.
*/
getListView().setOnCreateContextMenuListener(this);
/* Performs a managed query. The Activity handles closing and requerying the cursor
* when needed.
*
* Please see the introductory note about performing provider operations on the UI thread.
*/
Cursor cursor = managedQuery(
getIntent().getData(), // Use the default content URI for the provider.
PROJECTION, // Return the note ID and title for each note.
null, // No where clause, return all records.
null, // No where clause, therefore no where column values.
NotePad.Notes.DEFAULT_SORT_ORDER // Use the default sort order.
);
最佳答案
NoteList是App的主要入口点。请参阅 AndroidManifest.xml 以查看 Launcher 和 Main intent 过滤器
<activity android:name="NotesList" android:label="@string/title_notes_list">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.EDIT" />
<action android:name="android.intent.action.PICK" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="vnd.android.cursor.dir/vnd.google.note" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.GET_CONTENT" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="vnd.android.cursor.item/vnd.google.note" />
</intent-filter>
</activity>
每个 Activity 都由一个 Intent 启动。在 Activity 中调用 getIntent()。此调用返回启动它的 Intent 对象。在记事本中,NoteID -(这是一个 URI)从一个 Activity 传递到 Intent 对象中作为参数。
关于android - 记事本问题 : getIntent() and set data (by reference? ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8654599/