Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/212.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
帮助在Android上启动intent_Android_Android Intent_Android Layout - Fatal编程技术网

帮助在Android上启动intent

帮助在Android上启动intent,android,android-intent,android-layout,Android,Android Intent,Android Layout,我正试图从中学到一些东西。我想看看他们是如何实现他们在I/O上谈论的UI模式的 在HomeActivity中,他们使用以下代码启动NotesActivity: Notes类位于ScheduleContract类中,它看起来像: public static class Notes implements NotesColumns, BaseColumns { public static final Uri CONTENT_URI = BASE_CONTENT_URI.

我正试图从中学到一些东西。我想看看他们是如何实现他们在I/O上谈论的UI模式的

在HomeActivity中,他们使用以下代码启动NotesActivity:

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);
    }
}
我看不出这段代码到底做了什么,以及它如何在加载notes的情况下启动NotesActivity。我也不明白URI在new中作为第二个参数使用的方式和原因: IntentIntent.ACTION\u视图,Notes.CONTENT\u URI。
我在谷歌上搜索解释,但没有找到简单的解释和简单的例子。我猜Notes类是用来指向并格式化数据注释,然后不知何故启动了NotesActivity,但我不知道具体是如何启动的。

在Android中,你从来不会启动特定的应用程序,至少不会直接启动。您要做的是创建一个,它是要执行的操作的抽象描述:

意图提供了一种便利 执行后期运行时绑定 在不同的代码之间 应用。它最重要的用途 正在开展活动,, 在那里它可以被认为是胶水 活动之间。它基本上是一个 持有数据的被动数据结构 对要执行的操作的抽象描述 将被执行。主要部分 意向书中的信息包括:

行动-针对 被执行,例如 , 等等

数据-要操作的数据, 例如,在 联系人数据库,表示为

每当你想启动另一个应用程序,发送短信,选择联系人,启动摄像头等,你只需创建并启动一个意图,然后安卓自己决定应该启动什么应用程序

因此,以Notes活动为例:

startActivity(new Intent(Intent.ACTION_VIEW, Notes.CONTENT_URI));
第一个参数Intent.ACTION\u VIEW告诉用户,这个Intetwill将向用户显示一些内容。第二个参数Notes.CONTENT_URI是Notes活动的统一资源标识符。在您的示例中,如果您想打开带有特定注释的活动,URI还可以包含一个ID。结果是为用户显示Notes活动


如果您需要更多信息,我建议您阅读和,其中详细解释了这些概念

谢谢,我使用连接了Intent的基础知识。在我上面的例子中,他们使用的是内容提供者,URI指向存储在该提供者中的注释。
startActivity(new Intent(Intent.ACTION_VIEW, Notes.CONTENT_URI));