且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

删除活动后作为默认启动器如何在android中启动活动

更新时间:2023-01-25 17:25:27

这是不可能的。

因为当您将活动类别删除为Launcher时,Android系统将无法了解在请求打开应用程序时需要启动哪个活动。

因此你必须在Manifest.xml文件中指定Launcher活动,就像这样,

That is impossible.
Because as you removed the category of activity as Launcher, the Android system won't be able to understand which activity need to be started when application is requested to be opened.
Therefore you must specify Launcher activity in Manifest.xml file, like this,
<activity android:name=".ExampleActivity" android:icon="@drawable/app_icon">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>



要解决此问题,您需要使用明确意图

您不希望其他应用程序可用的活动应该没有意图过滤器,您可以启动他们自己使用明确的意图。



阅读此意图 [ ^ ]


To overcome this, you need to use Explicit Intents,
Activities that you don't want to make available to other applications should have no intent filters and you can start them yourself using explicit intents.

Read this Intent[^]

Quote:

显式意图指定按名称开始的组件(完全限定的类名)。您通常会使用显式意图在您自己的应用中启动组件,因为您知道要启动的活动或服务的类名。例如,启动一个新活动以响应用户操作或启动服务以在后台下载文件。

Explicit intents specify the component to start by name (the fully-qualified class name). You'll typically use an explicit intent to start a component in your own app, because you know the class name of the activity or service you want to start. For example, start a new activity in response to a user action or start a service to download a file in the background.



例如,


for example,

Intent intent = new Intent(this, SignInActivity.class);
startActivity(intent);





-KR



-KR