【问题标题】:What is the difference between intent and intent filters?Can i declare intent filter in activity instead of manifest?意图和意图过滤器有什么区别?我可以在活动中声明意图过滤器而不是清单吗?
【发布时间】:2019-08-25 05:07:00
【问题描述】:

请清楚地告诉我们什么是意图和意图过滤器。我可以在组件中创建意图过滤器而不是在清单中声明。请告诉我们。

意图actionIntent=新意图(动作); //if(action.matches("ACTION_SEND")){

        actionIntent.putExtra(Intent.EXTRA_EMAIL,"xxx@gmail.com");

        actionIntent.putExtra(Intent.EXTRA_SUBJECT, "first example");
        actionIntent.putExtra(Intent.EXTRA_TEXT, "prepating for interivew-test examples");

        //need this to prompts email client only
        actionIntent.setType("message/rfc821");
        startActivity(Intent.createChooser(actionIntent, "Choose an Email client :"));

清单:

        <category android:name = "android.intent.category.DEFAULT" />

     </intent-filter>

【问题讨论】:

    标签: android-intent android-manifest intentfilter


    【解决方案1】:

    Intent和Intent过滤器的区别

    Intent 用于开始一个新的活动。如果需要,它们会将信息从一项活动传送到另一项活动。以类似的方式,它们也用于启动服务。

    另一边的 Intent-filter 根据 Intent 的动作、数据和类别告诉我们即将接收的组件类型。

    不,我们不能声明除 manifest 之外的意图过滤器。

    这里是更多信息的链接https://developer.android.com/guide/components/intents-filters

    【讨论】:

    • 我们应该以编程方式创建意图过滤器吗?
    • 只有一个问题,如何创建意图过滤器。当它们应该在 manifest 中声明时。根据需要我们可以给出类别、动作和数据。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-16
    • 1970-01-01
    • 2017-05-21
    相关资源
    最近更新 更多