Android 活动重启
我在重新启动活动时遇到了困惑。我有两个功能可以很好地完成同一任务。请指导我哪个最好,为什么?
public void restart()
{
Intent intent = getIntent();
overridePendingTransition(0, 0);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
finish();
overridePendingTransition(R.anim.fade,R.anim.fade);
startActivity(intent);
}
或
public void restart()
{
onCreate();
}
提前致谢?
I am having a confusion in restarting an activity.. I have two function that works well for the same task. Please guide me which is best and why?
public void restart()
{
Intent intent = getIntent();
overridePendingTransition(0, 0);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
finish();
overridePendingTransition(R.anim.fade,R.anim.fade);
startActivity(intent);
}
or
public void restart()
{
onCreate();
}
Thanks In advance?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为这是满足您要求的更清洁的方式。
I think this is a cleaner way for your requirement.
系统中的活动作为活动堆栈进行管理。当一个新的 Activity 启动时,它会被放置在堆栈的顶部并成为正在运行的 Activity——之前的 Activity 始终保留在堆栈中的下方,并且在新 Activity 退出之前不会再次来到前台。
有关详细信息,请参阅活动
Activities in the system are managed as an activity stack. When a new activity is started, it is placed on the top of the stack and becomes the running activity -- the previous activity always remains below it in the stack, and will not come to the foreground again until the new activity exits.
for more info see Activity
此内容已之前发布:
This has been posted before: