两个或多个活动(每个活动都具有带有action = android.intent.action.ACTION_MAIN的Intent过滤器)是什么意思? [英] What does it mean when two or more activities, each having intent-filter with action=android.intent.action.ACTION_MAIN?

查看:70
本文介绍了两个或多个活动(每个活动都具有带有action = android.intent.action.ACTION_MAIN的Intent过滤器)是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

医生说 https://developer.android.com/reference/android/content/Intent.html#ACTION_MAIN 是一个入口点.

示例代码:

 <activity android:name="org.A.A"
            android:theme="@style/NoTitle"
            android:screenOrientation="behind"
            android:launchMode="singleTask">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
            </intent-filter>
        </activity>

        <activity android:name="org.A.C"
            android:theme="@style/NoTitle"
            android:launchMode="singleTop"
            android:screenOrientation="behind">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
            </intent-filter>
        </activity>

        <activity android:name="org.A.B"
            android:theme="@style/NoTitle"
            android:launchMode="singleTop"
            android:screenOrientation="behind">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
            </intent-filter>
        </activity>

1)那么使用android.intent.action.ACTION_MAIN充当父组件(父组件,我是指活动,接收者或服务)的入口点吗?

1) So using android.intent.action.ACTION_MAIN acts as an entry point to the parent component (parent component I mean the activity or receiver or service)?

2)如果是,则从此处输入入口点,因为未提及CATEGORY.

2) If yes, Entry point from where, as there is no CATEGORY mentioned.

推荐答案

Android应用由不同的组件组成.例如活动服务 BroadcastReceiver ContentProvider ,并且每个组件都可以充当入口点".

Android apps are composed of different components. e.g. Activity, Service, BroadcastReceiver, and ContentProvider and each component can act as an entry point of the app.

让我们以活动为例,您已通过以下操作在应用程序中定义了一个活动

Let's take activity as an example, you have defined an activity in your application with following action

<intent-filter>
     <action android:name="com.yourapp.SOME_ACTION" />
     <category android:name="android.intent.category.DEFAULT"/>
</intent-filter>

并且我出于以下意图在我的应用中开始了一项活动.

and I start an activity in my app with following intent.

Intent intent = new Intent("com.yourapp.SOME_ACTION"); // same action
startActivity(intent);

现在会发生什么?系统将使用 com.yourapp.SOME_ACTION 动作搜索活动,如果找到一个活动(在当前情况下,它将是您使用 com.yourapp.SOME_ACTION 创建的活动.您的应用),它将启动您的应用(如果尚未启动),并在您的应用中打开该活动.

Now what will happen? System will search for activities with com.yourapp.SOME_ACTION action and if it finds one (in current scenario, it will be activity you have created with com.yourapp.SOME_ACTION in your app), it will start your app (if it is not already started) and will open the activity in your app.

现在,我可以通过将 Activity com.yourapp.SOME_ACTION 结合使用,来进入.如果使用其他组件,也会发生同样的事情.

See, now I can enter into your app by using Activity with com.yourapp.SOME_ACTION. Same thing happens in case of other components.

这篇关于两个或多个活动(每个活动都具有带有action = android.intent.action.ACTION_MAIN的Intent过滤器)是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆