简体   繁体   English

如果孩子已经完成,则阻止参加家长活动

[英]Prevent going to parent activity if child has finished

I have some kind of a login activity which returns to main if login successfull. 我有某种登录活动,如果登录成功,它会返回到main。 But after that, if user presses hardware "back" button, main activity is restarting for some reason... 但是之后,如果用户按下硬件“后退”按钮,则主要活动由于某种原因而重新启动...
It seems like it is going to previous (login) activity, but since it has already finished, parent activity is restarted. 似乎要进行上一个(登录)活动,但是由于它已经完成,因此父活动将重新启动。
I have tried using <activity android:noHistory="true"> on login activity in manifest. 我尝试对清单中的登录活动使用<activity android:noHistory="true"> startActivityForResult() is not a solution for me as well. startActivityForResult()对我来说也不是一个解决方案。 Problem remains. 问题仍然存在。

Can you help me with any other ideas? 您能帮我其他想法吗?

UPD: I am calling finish() when going back to main activity UPD:回到主要活动时,我正在调用finish()

This is probably because you haven't finished your activity when you're 'returning' to main. 这可能是因为您在“返回”主界面时尚未完成活动。 Check where you create your intents, always finish activities you do not want to be accessed via the back stack. 检查要创建你的意图,总是做完活动,你希望通过后退堆栈进行访问。

try use this after each startActivity() 尝试在每个startActivity()之后使用它

startActivity(intent);//you already have this
finish();//add just this .. and report

Do not call finish() inside of onBackPressed() method. 不要在onBackPressed()方法内部调用finish() Android / OS will do it for you automatically. Android / OS会自动为您完成此操作。

Call finish() only If login was ok and you want to close the login activity. 仅在登录正常并且要关闭登录活动时才调用finish() Of course only if main activity present in the back stack. 当然,仅当主活动存在于后堆栈中时。

If back stack contains no main activity, so open it by using of common startActivity method. 如果后堆栈不包含任何主要活动,请使用通用的startActivity方法将其打开。 Also check this answer to remove an activity from the back stack. 还要检查此答案以从后堆栈中删除活动。

Problem is solved by forcely exiting the whole application in main activity's onBackPressed() method. 通过在主要活动的onBackPressed()方法中强制退出整个应用程序来解决问题。 Although, it doesn't seem like a clear solution to me. 虽然,对我来说这似乎不是一个明确的解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何知道活动已经结束? - How to know activity has been finished? 孩子已经有父母了 - The child already has a parent 指定的孩子已经有一个父母。 你必须首先对孩子的父母打电话removeView()(与片段和ViewPager活动) - The specified child already has a parent. You must call removeView() on the child's parent first (Activity with fragment and ViewPager) 刷新孩子的家长活动? - Refreshing parent activity from child? 如何将值从父级活动传递到子级活动,以及如何在子级活动退出时刷新父级活动 - How to pass value from parent activity to child activity and on child activity exit, refresh the parent activity 指定的孩子已经有父母 - Specified child already has parent 父级完成后,子级工作流程会继续运行吗? (ChildPolicy.ABANDON) - Will Child workflow continue to run after parent is finished? (ChildPolicy.ABANDON) 如何判断活动的先前实例中的线程已完成? - How to tell a thread from a previous instance of your activity has finished? 使用setDisplayHomeAsUpEnabled返回清单中的PARENT_ACTIVITY的问题 - issue with going back to PARENT_ACTIVITY in manifest, using setDisplayHomeAsUpEnabled 防止子类覆盖父类中的方法 - Prevent child class from overriding a method in parent
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM