问题描述
我知道这可能非常简单,但是我无法弄清楚.
I know this is probably extremely simple, but I just can not figure it out.
我正在尝试在操作后重新加载/重新创建活动.我知道我可以使用:
I'm trying to reload/recreate an activity after an action. I know I could just use:
Intent intent = getIntent();
finish();
startActivity(intent);
但是在阅读网站上的答案时,我被告知要在11个api之后使用'recreate()'.任何帮助将不胜感激,谢谢!
But in reading through answers on the site I'm told to use 'recreate()' after 11 api. Any help would be appreciated, thanks!
推荐答案
同时使用重新创建方法的工作原理是
While using the recreate method works by doing
this.recreate()
它仅在API级别11中添加.如果要包括更多设备,则可以检查API级别并实现recreate方法和
It was only added in API level 11. If you want to include more devices you can check the API level and implement both the recreate method as well as
Intent intent = getIntent();
finish();
startActivity(intent);
您可以通过以下类似的if语句来使用两者:
You can use both by making an if statement like...
if (android.os.Build.VERSION.SDK_INT >= 11) {
//Code for recreate
recreate();
} else {
//Code for Intent
Intent intent = getIntent();
finish();
startActivity(intent);
}
这篇关于如何调用recreate()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!