当我旋转我的设备时,这又为他的课程充电。例如,如果我再次将定向费用更改为Google,则会进行Google搜索。
我尝试过:
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
setContentView(R.layout.principal);
}
和onRestoreInstanceState和onSaveInstanceState。但我的问题仍然存在。如果有人可以帮助我做一个例子或说明如何做到这一点,我将不胜感激。
感谢的!
我已经解决了这个问题,我需要做if(savedInstanceState == null):
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.principal);
webview.setWebViewClient(new WebViewClient());
if (savedInstanceState == null)
{
webview.loadUrl("http://www.apple.es");
}
}
@Override
protected void onSaveInstanceState(Bundle outState)
{
super.onSaveInstanceState(outState);
// Save the state of the WebView
webview.saveState(outState);
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState)
{
super.onRestoreInstanceState(savedInstanceState);
// Restore the state of the WebView
webview.restoreState(savedInstanceState);
}
我希望比我的问题和我的解决方案对某人有所帮助!
答案 0 :(得分:0)
在AndroidManifest文件中添加configChanges。 例如:
<activity android:name="YourActivityName"
android:configChanges="orientation">
</activity>
并将当前网址保存在本地变量中并将其加载到onConfigChanges
中@Override
public void onConfigurationChanged(Configuration newConfig) {
yourWebView.loadUrl(yourUrl);
}
答案 1 :(得分:0)
使用以下代码
public void onConfigurationChanged(Configuration newConfig) {
yourWebView.loadUrl(yourUrl);
}
答案 2 :(得分:0)