Android AppWidget 配置 - 在新任务中开始 [英] Android AppWidget Configuration - Start in new task

查看:28
本文介绍了Android AppWidget 配置 - 在新任务中开始的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经搜索、搜索和搜索了这个!

I've searched and searched and searched for this!

所以我有一个应用小部件,它有一个配置活动,我可以在按下应用上的按钮时打开它.场景是:

So I've got an app widget and it has a configuration activity that I can open when pressing a button on the app. The scenario is:

已打开应用程序.

使用主页按钮关闭应用程序.

Closed the app with the home button.

选择添加我的小部件

我已经配置了小部件.

放在我的主屏幕上

然后使用小部件上的按钮再次打开配置活动.

Then open the configuration activity again with the button on the widget.

按返回取消新配置将使我回到应用程序.

Cancel the new config by pressing back will put me back into the app.

当按下时我只想回家.

基本上我要问的是.如何在它自己的任务/堆栈中启动配置活动?

Basically what I'm asking is. How do I start the configuration activity in it's own task/stack?

我已经研究过意图过滤器,但我不太确定,或者可能与它所在的包有关,或者可能只是不可能!

I've looked into intent filters but I'm just not quite sure, or maybe it's something to do with the package it's in, or maybe it's just not possible!

我想这可能与我用来启动配置活动的意图有关

I suppose it may have something to do with the intent I use to launch the config activity

 Intent configIntent = new Intent(this, Configuration.class);
 configIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);      
 remoteView.setOnClickPendingIntent(R.id.config, PendingIntent.getActivity(this, 0, configIntent, PendingIntent.FLAG_UPDATE_CURRENT));

也许因为我以this"作为上下文启动它,它总是会在我的应用程序堆栈中启动...但待处理的意图 api 是:PendingIntent API 1"请注意,该活动将在现有活动的上下文之外启动"

Perhaps because I launch it with 'this' as the context, it will always start in my applications stack... but the pending intent api is: PendingIntent API 1 "Note that the activity will be started outside of the context of an existing activity"

所以,是的,我现在就不再说话了,因为我只是在兜圈子!

So yeah I'll stop talking now as I just end up going in circles!

编辑

所以在清单中尝试了 android:launchMode="singleInstance" ,就像声明的那样.这有效,但是它阻止了startActivityForResult"行为的正常工作.(这是配置活动的全部原因)得到错误:

So tried android:launchMode="singleInstance" in the manifest like was stated. This worked however it stops the 'startActivityForResult' behaviour working correctly. (which is the whole reason for a config activity) Get the error:

WARN/ActivityManager(59): Activity 正在作为新任务启动,因此取消 Activity 结果.

WARN/ActivityManager(59): Activity is launching as a new task, so cancelling activity result.

所以还没有找到解决办法.

So still haven't found a solution.

推荐答案

好的 :-) 需要:

android:taskAffinity=""

在清单中,将任务关联设置为空字符串允许 Activity 在它自己的堆栈中启动,因为它与应用程序的其余部分没有关联".

in the manifest, setting the task affinity to an empty string allows for the activity to start in it's own stack, as it is not 'affiliated' with the rest of the application.

更新

我已将任务关联更改为:android:taskAffinity="com.my.package.alternative.task"每次我启动该活动时,它都会在历史"中多次出现.所以它现在从它自己的堆栈开始,但与同一活动的其他实例共享.

还需要将 Flag Intent.FLAG_ACTIVITY_NO_HISTORY 添加到您的意图 :-) 当您按住"主页按钮时,这会阻止您在历史记录中多次获取应用程序.

Also need to add the Flag Intent.FLAG_ACTIVITY_NO_HISTORY to your intent :-) this stops your getting your application multiple time's in the history when you 'press and hold' the home button.

更新

我注意到 FLAG_ACTIVITY_NO_HISTORY 没有按照我的意愿行事,我已将其删除并添加:

I've noticed FLAG_ACTIVITY_NO_HISTORY wasn't doing what I wanted, I've removed it and added:

android:excludeFromRecents="true"

也进入清单中的活动标签.该活动现在的行为就像我想要的那样:-)

into the activity tag in the manifest as well. The activity now behaves like I want :-)

从以下链接中得到了这个答案:任务&返回栈 |管理任务 |附属标签

Got this answer from the following link trail: Tasks & Back Stack | Managing Tasks | Affiliation Tag

这篇关于Android AppWidget 配置 - 在新任务中开始的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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