如何让第二个启动器始终在指定的活动中打开应用程序
在我的应用程序中,我使用此清单条目指定了可以从启动器启动的第二个活动:
<activity
android:name=".Lists.ListOfListsActivity"
android:icon="@drawable/ic_launcher_lists"
android:launchMode="singleTop"
android:label="@string/lists_activity_name" >
<!-- An Intent filter so that the Lists activity shows in the Launcher -->
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
假设我在“主”活动中打开应用程序,然后按主页键。我的应用程序仍将运行,但在后台运行。
稍后,用户从主屏幕选择“ListsOfListsActivity”的启动器图标。
这会将应用程序带到前台,但不是在“ListOfListsActivity”,而是在它进入后台时的当前活动(例如在“main”活动)。
这很令人困惑,因为用户选择了“ListOfListsActivity”,但显示的是另一个。然后他们必须导航到它。
通过为“ListOfListsActivity”指定 launchMode =“singleTask”,我可以更好地工作,但在该模式下,它无法从另一个活动启动以获得结果(startActivityForResult()),并且我需要能够做到这一点来选择一个列表...
问题: - 如何指定一个意图过滤器,将强制一个活动到前台并成为选定的活动,无论应用程序的当前状态及其当前活动如何?
In my application, I have specified a second activity that can be launched from the launcher, using this manifest entry:
<activity
android:name=".Lists.ListOfListsActivity"
android:icon="@drawable/ic_launcher_lists"
android:launchMode="singleTop"
android:label="@string/lists_activity_name" >
<!-- An Intent filter so that the Lists activity shows in the Launcher -->
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Let's say I have the app open at the "main" activity then press the home key. My app will still be running, but in background.
Later the user selects the launcher icon I have for "ListsOfListsActivity" from the homescreen.
This will bring the application to the foreground, but NOT at the "ListOfListsActivity", but at whatever it's current activity was when it went to the background (e.g. at the "main"activity).
This is confusing, as the user selected the "ListOfListsActivity" but is shown another one. Then they have to navigate to it.
I had this working better, by specifying launchMode = "singleTask" for the "ListOfListsActivity", but in that mode it cannot be launched from another activity for a result (startActivityForResult() ), and I need to be able to do that to pick a list...
Question:
- how to specify an intent-filter that will force an activity to the foreground and be the selected activity, no matter what the current status of the application and it's current activity??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的最终实现是为我想要独立于启动器启动的每个活动定义不同的 taskAfinity 字符串。
这样,每个“快捷方式”总是启动我想要的活动,但我无法避免的缺点是用户可能有多个任务,其中包含我的应用程序中的活动,并且可能打开/活动相同的活动在不同的任务中......
My final implementation was to define a different taskAfinity string for each activity I wanted to launch independently from the Launcher.
That way, each "shortcut" always launches the activity I want, but the downside that I have not been able to avoid is that the user may have multiple tasks with an activity from my application in it, and maybe the same activity open/active in different tasks....