我在Android文档指南开发人员之后创建了代码,但代码显然是正确的但是要转动移动屏幕它的行为方式不应该是旋转屏幕并继续处于相反的状态他回到了主页。有什么问题吗?
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.i(TAG,"onCreate");
wv = (WebView) findViewById(R.id.webView1);
wv.getSettings().setJavaScriptEnabled(true);
wv.loadUrl("http://www.uol.com.br");
}
@Override
protected void onStart(){
super.onStart();
Log.i(TAG, "onStart");
}
@Override
protected void onRestart(){
super.onRestart();
Log.i(TAG, "onRestart");
}
@Override
protected void onPause(){
super.onPause();
Log.i(TAG, "onPause");
}
@Override
protected void onResume(){
super.onResume();
Log.i(TAG, "onResume");
}
@Override
protected void onDestroy(){
super.onDestroy();
Log.i(TAG, "onDestroy");
}
@Override
protected void onStop(){
super.onStop();
Log.i(TAG, "onStop");
}
@Override
protected void onSaveInstanceState(Bundle outState){
super.onSaveInstanceState(outState);
wv.saveState(outState);
Log.i(TAG,"onSaveInstanceState");
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState){
super.onRestoreInstanceState(savedInstanceState);
wv.restoreState(savedInstanceState);
Log.i(TAG,"onRestoreInstanceState");
}
答案 0 :(得分:0)
当我运行你的代码时,它似乎工作得很好。您正在正确保存和恢复Webview状态,因此webview会在轮换之前正确选择用户。
但有一点,点击您加载的网页上的任何链接都会在默认浏览器中打开,而不是您的应用。也许这与您所看到的问题有关?
将此添加到您的onCreate()以允许在您的应用中打开网页:
wv.setWebViewClient(new WebViewClient(){
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});