在Android中启动其他活动时如何完成活动? [英] How to finish Activity when starting other activity in Android?
问题描述
我之前无法完成活动.我想开始另一个活动并完成当前的活动.当我使用 finish
时,它没有退出当前活动.
I have problems to finish the activity before. I want to start another activity and finish the current activity. When I used finish
it didn't exit the current activity.
我之前如何退出活动?
推荐答案
您需要先使用 startActivity
intent
您当前的 context
到另一个活动>.之后,您可以从重定向的位置完成
您当前的activity
.
You need to intent
your current context
to another activity first with startActivity
. After that you can finish
your current activity
from where you redirect.
Intent intent = new Intent(this, FirstActivity.class);// New activity
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
finish(); // Call once you redirect to another activity
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
- 清除活动堆栈.如果您不想清除活动堆栈.那么请不要使用那个标志.
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
- Clears the activity stack. If you don't want to clear the activity stack. PLease don't use that flag then.
这篇关于在Android中启动其他活动时如何完成活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!