如何退出当前活动主屏幕(不使用"家庭和QUOT;按钮)? [英] How to exit current activity to homescreen (without using "Home" button)?

查看:148
本文介绍了如何退出当前活动主屏幕(不使用"家庭和QUOT;按钮)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我相信这将有答案,但我证明了无法找到它。所以,请原谅我的冗余。

I am sure this will have been answered but I proved unable to find it. So please excuse my redundancy.

我所试图做的是模拟的主页按钮,需要一个回Android的主屏幕上。因此,这里是什么原因导致我的问题:

What I am trying to do is emulating the "Home" button which takes one back to Android's homescreen. So here is what causes me problems:

  • 在我有3个发射活动。第一个(其连接到主屏幕图标)仅仅是一个(密码保护)配置活动。它不会被由用户使用(只是管理员)
  • 一个其他2(两者通过一个应用程序窗口小部件访问)是一个问卷调查应用程序。我允许通过后退按钮或GUI后退按钮跳回问题之间为好。当调查结束后我总结给出的答案,并提供了一​​个完成按钮,应采取用户返回到主屏幕。

有关问卷应用程序,我用一个单一的活动(称为ItemActivity)自称(是递归以及使用意图是什么时候?)跳从一个问题到另一个问题:

For the questionnaire app I use a single activity (called ItemActivity) which calls itself (is that recursion as well when using intents?) to jump from one question to another:

Questionnaire.serializeToXML();  
Intent i = new Intent().setClass(c, ItemActivity.class);  
if(Questionnaire.instance.getCurrentItemNo() == Questionnaire.instance.getAmountOfItems()) {  
    Questionnaire.instance.setCompleted(true);  
} else Questionnaire.instance.nextItem();  
startActivity(i);

最后的屏幕显示类似感谢您参与还有以前描述的按钮,​​应该采取一回到主屏幕。但我真的不明白如何退出活动正常。我已经如使用 this.finish(); 但是这个奇怪的祭起了谢谢你的屏幕了。所以,我怎么能仅仅通过跳回到主屏幕??退出

The final screen shows something like "Thank you for participating" as well as the formerly described button which should take one back to the homescreen. But I don't really get how to exit the Activity properly. I've e.g. used this.finish(); but this strangely brings up the "Thank you" screen again. So how can I just exit by jumping back to the homescreen??

对不起,inconvinience。
问候,
Steff

Sorry for the inconvinience.
Regards,
Steff

推荐答案

听起来好像发生了什么事是,你有你的活动的多个副本在同一时间打开。你开始一个活动的新实例每次你只是增加新的堆栈 - 所有的旧的活动仍然存在。当你调用 this.finish(),它只是显示你的下一个最近所打开的活动。我不知道为什么这是自presumably的谢谢你的屏幕,只有在最后被打开了,但我并不完全按照顺序的活动得到调用

It sounds like what's happening is that you've got multiple copies of your activities open at the same time. Every time you start a new instance of an activity you're just adding new ones to the stack - all the old activities are still there. When you call this.finish(), it's just showing you the next most recent activity that was open. I'm not sure why that's the "Thank you" screen since presumably that only gets opened at the end, but then I don't fully follow the sequence your activities get called in.

您可以尝试做什么来解决这个问题可以是:1)使用完成()开始一个新的活动,为不同的问题(这样就只有后,每次曾经一个问题活动同时打开),或2),看看你是否可以使用意向标志CLEAR_TOP的。启动而杀死任何可能已经在堆栈中被其上方的目标活动。例如,如果您有活动:A,B,C,C,C,C,C(等每个问题),然后开始用CLEAR_TOP会杀死B的所有实例和C.你可以适应这个到你的程序结构通过改变第一屏,用户可以看到当他们开始调查问卷。这将显示一个默认的欢迎消息,一键启动调查。然而,如果它的开始与捆绑在一起的意图的特定值,这将显示谢谢消息。

What you can try doing to fix it is either: 1) use a finish() every time after starting a new activity for a different question (so that there's only ever one question activity open at a time), or 2) see if you can make use of the intent flag CLEAR_TOP. That starts the target activity while killing anything that might have been above it in the stack. For example if you have activities: A, B, C, C, C, C, C (etc for each question), then starting A with CLEAR_TOP will kill off all instances of B and C. You could fit this into your program structure by changing the first screen the user sees when they start a questionnaire. This would show a 'welcome' message by default with a button to start the questionnaire. However, if it's started with a particular value bundled with the intent, it would display the "Thank you" message.

如果你这样做,那么一旦你完成()活动A,用户将返回到哪里,它们就会开始你的应用程序之前 - presumably的如果主屏幕上它是起源于一个appwidget。

If you do that, then once you finish() activity A, the user will be returned to wherever they were before they started your app - presumably the homescreen if it's started with an appwidget.

这篇关于如何退出当前活动主屏幕(不使用"家庭和QUOT;按钮)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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