How to exit current activity to homescreen (without using “Home” button)?

≯℡__Kan透↙ 提交于 2019-12-08 03:34:29

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.

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!