所以我试图理解NotePad示例中的所有代码,但是我遇到了一些困难:
首先,如何判断我们的项目是从“X”文件开始的?像一个“索引”文件..?
(我猜它是从NoteList页面开始的)在这个NoteList页面中,我们使用getIntent()获取当前意图,然后获取其中的数据:但是:
getIntent().getData()
:它是通过“reference”传递还是类似的?那么使用新的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.
);
答案 0 :(得分:2)
NoteList是App的主要入口点。请参阅AndroidManifest.xml以查看Launcher和主要意图过滤器
<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>
每个活动都由Intent启动。在Activity中调用getIntent()。此调用返回启动它的Intent对象。在记事本中,NoteID - (这是一个URI)从一个活动传递给Intent对象中的参数。