Android“您要使用哪个应用程序”重定向到活动时的对话框

问题描述 投票:0回答:2

这些是我的两项活动的两个意图过滤器:

开始活动

  <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.HOME" />

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

我正在家庭活动中,当我打电话时:

  activity.startActivity(new Intent("android.intent.action.MAIN"));

Android 显示一个对话框,询问我想使用哪个应用程序来继续。 有好心人帮我解释一下为什么吗?

编辑

我要说得更清楚: StartActivity -> 包含登录和登录操作 HomeActivity -> 包含应用程序的大部分内容

我的场景: 我成功登录,现在我在 HomeActivity 中,但是当我注销并重定向到启动活动时,android 会显示一个对话框“您想使用哪个应用程序来完成此操作?” (或类似的东西)而不是将我重定向到 StartActivity

android
2个回答
0
投票

我不知道你为什么需要

Action HOME
,但看起来你的问题是
Category DEFAULT
。根据 android 文档,该类别被定义为:

Set if the activity should be an option for the default action (center press) to perform on a piece of data. Setting this will hide from the user any activities without it set when performing an action on some data. Note that this is normally -not- set in the Intent when initiating an action -- it is for use in intent filters specified in packages.
Constant Value: "android.intent.category.DEFAULT"

所以我认为将其更改为适合您需要的正确选项将解决问题。只是一个建议!

了解更多信息:http://developer.android.com/reference/android/content/Intent.html#CATEGORY_DEFAULT


0
投票

不确定是否已解决,但我使用

避免了该问题
 activity.startActivity(new Intent(activity,StartActivity.class));
© www.soinside.com 2019 - 2024. All rights reserved.