gpt4 book ai didi

Android - 如何从小部件启动 Activity 并返回主屏幕

转载 作者:行者123 更新时间:2023-11-29 16:25:53 25 4
gpt4 key购买 nike

我有一个小部件,单击它会从与小部件相同的应用程序打开一个 Activity 。当通过按钮关闭/关闭 Activity 时,如果应用程序之前打开/在内存中,用户将看到完整的应用程序窗口。有没有一种方法可以让 Activity 完成并返回到主屏幕而不是应用程序的现有实例?

Intent i = new Intent(this,RateIt.class);
i.putExtra("com.sporadicsoftware.NetQ.movie_id",aMovie.title_id);
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET|Intent.FLAG_ACTIVITY_NO_HISTORY|Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(context,
0, i, PendingIntent.FLAG_UPDATE_CURRENT);
updateViews.setOnClickPendingIntent(R.id.movie_one_title, pendingIntent);

最佳答案

查看 UI 指南 "Notifications should let the user easily get back to the previous activity"对于类似情况以及 Activities and Tasks应用程序基础框架主题部分。

根据您的需要,您可以使用 Intent 标志 FLAG_ACTIVITY_NEW_TASK 结合为您要单独打开的 Activity 设置个人亲和性。您可以设置 taskAffinity <activity> 的属性 list 中的元素为空字符串。如果您始终仅将此 Activity 与应用程序的其余部分分开使用,这将是一个很好的解决方案。

来自documentation :

android:taskAffinity

The task that the activity has an affinity for. Activities with the same affinity conceptually belong to the same task (to the same "application" from the user's perspective). The affinity of a task is determined by the affinity of its root activity. The affinity determines two things — the task that the activity is re-parented to (see the allowTaskReparenting attribute) and the task that will house the activity when it is launched with the FLAG_ACTIVITY_NEW_TASK flag.

By default, all activities in an application have the same affinity. You can set this attribute to group them differently, and even place activities defined in different applications within the same task. To specify that the activity does not have an affinity for any task, set it to an empty string.

If this attribute is not set, the activity inherits the affinity set for the application (see the <application> element's taskAffinity attribute). The name of the default affinity for an application is the package name set by the <manifest> element.

关于Android - 如何从小部件启动 Activity 并返回主屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3711161/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com