我在我的應用中有Webview
。當我打開我的應用程序並切換到另一個應用程序或只是進入主屏幕,然後重新打開我的應用程序。 Webview
加載我設置的網址以加載onCreate()
方法,而不是我在關閉應用程序之前訪問的網址。Webview每當活動聚焦時加載相同的url
我保存的網址使用此方法sharedprefrences的幫助: http://developer.android.com/training/basics/data-storage/shared-preferences.html
標準savedUrl是它加載在第一onCreate()
方法標準的URL,但它讓我寫的值還有應用程序暫停時重置?
某些日誌:
02-05 09:46:57.443 24132-24132/com.example.okke.testwebapp02 D/SAVING_URL: http://www.remotepressure.com/
02-05 09:46:57.453 24132-24132/com.example.okke.testwebapp02 I/chromium: [INFO:CONSOLE(1)] "Uncaught TypeError: Cannot set property 'value' of null", source: (1)
02-05 09:46:57.453 24132-24132/com.example.okke.testwebapp02 I/chromium: [INFO:CONSOLE(1)] "Uncaught TypeError: Cannot set property 'value' of null", source: (1)
02-05 09:46:57.453 24132-24132/com.example.okke.testwebapp02 I/chromium: [INFO:CONSOLE(1)] "Uncaught TypeError: Cannot read property 'click' of null", source: (1)
02-05 09:47:00.201 24132-24132/com.example.okke.testwebapp02 D/cr_Ime: [ImeAdapter.java:571] focusedNodeChanged
02-05 09:47:00.214 24132-24132/com.example.okke.testwebapp02 D/cr_Ime: [ImeAdapter.java:213] updateKeyboardVisibility: type [0], flags [0], show [true]
02-05 09:47:00.214 24132-24132/com.example.okke.testwebapp02 D/cr_Ime: [AdapterInputConnection.java:178] updateState [] [0 0] [-1 -1] [true]
02-05 09:47:00.465 24132-24132/com.example.okke.testwebapp02 D/cr_Ime: [ImeAdapter.java:571] focusedNodeChanged
02-05 09:47:00.489 24132-24132/com.example.okke.testwebapp02 W/cr_BindingManager: Cannot call determinedVisibility() - never saw a connection for the pid: 24132
02-05 09:47:00.878 24132-24132/com.example.okke.testwebapp02 D/SAVING_URL: http://www.remotepressure.com/welcome-page
02-05 09:47:00.888 24132-24132/com.example.okke.testwebapp02 I/chromium: [INFO:CONSOLE(1)] "Uncaught TypeError: Cannot set property 'value' of null", source: (1)
02-05 09:47:00.888 24132-24132/com.example.okke.testwebapp02 I/chromium: [INFO:CONSOLE(1)] "Uncaught TypeError: Cannot set property 'value' of null", source: (1)
02-05 09:47:00.888 24132-24132/com.example.okke.testwebapp02 I/chromium: [INFO:CONSOLE(1)] "Uncaught TypeError: Cannot read property 'click' of null", source: (1)
02-05 09:47:06.488 24132-24132/com.example.okke.testwebapp02 D/APP: PAUSE
02-05 09:47:06.638 24132-24132/com.example.okke.testwebapp02 D/cr_Ime: [AdapterInputConnection.java:499] finishComposingText
02-05 09:47:06.735 24132-24138/com.example.okke.testwebapp02 W/art: Suspending all threads took: 19.298ms
02-05 09:47:06.735 24132-24132/com.example.okke.testwebapp02 D/cr_Ime: [AdapterInputConnection.java:499] finishComposingText
02-05 09:47:09.386 24132-24132/com.example.okke.testwebapp02 D/cr_Ime: [InputMethodManagerWrapper.java:27] Constructor
02-05 09:47:09.387 24132-24132/com.example.okke.testwebapp02 D/cr_Ime: [ImeAdapter.java:241] attach
02-05 09:47:09.387 24132-24132/com.example.okke.testwebapp02 W/art: Attempt to remove non-JNI local reference, dumping thread
02-05 09:47:09.388 24132-24132/com.example.okke.testwebapp02 W/AwContents: onDetachedFromWindow called when already detached. Ignoring
02-05 09:47:09.389 24132-24132/com.example.okke.testwebapp02 D/cr_Ime: [InputMethodManagerWrapper.java:56] isActive: false
02-05 09:47:09.389 24132-24132/com.example.okke.testwebapp02 D/APP: CREATE
02-05 09:47:09.392 24132-24132/com.example.okke.testwebapp02 D/LOADING_URL: http://www.remotepressure.com
02-05 09:47:09.400 24132-24132/com.example.okke.testwebapp02 D/cr_Ime: [ImeAdapter.java:241] attach
02-05 09:47:09.404 24132-24132/com.example.okke.testwebapp02 D/APP: START
02-05 09:47:09.405 24132-24132/com.example.okke.testwebapp02 D/APP: RESUME`
保存的網址:
public void onPageFinished(WebView view, String url) {
if (fromLogin) {
//String javascript = "javascript:(function(){ document.getElementById('mib').value = 'aaa'; })()";
//String javascript = "javascript:document.forms[0].username.value = '"+test01+"';";
mWebView.loadUrl("javascript:var x = document.getElementById('modlgn-username').value = '" + userName + "';");
mWebView.loadUrl("javascript:var z = document.getElementById('modlgn-passwd').value = '" + passWord + "';");
/*mWebView.loadUrl("javascript:(function(){"+
"l=document.getElementById('form-login-submit');"+
"e=document.createEvent('HTMLEvents');"+
"e.initEvent('click',true,true);"+
"l.dispatchEvent(e);"+
"})()");*/
//var y = $document.getElementById('form-login-submit').click();");
//mWebView.loadUrl("http://www.google.com/");
mWebView.loadUrl("javascript: var y = document.getElementById('form-login-submit'); y.click();");
}
if (mWebView.getUrl() != null) {
SharedPreferences sharedpref = Web.this.getPreferences(Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedpref.edit();
String temp = mWebView.getUrl();
Log.d("SAVING_URL", temp);
editor.putString(getString(R.string.loaded_url), mWebView.getUrl());
editor.commit();
}
載入URL中onCreate()
Log.d("LOADING_URL", getResources().getString(R.string.loaded_url));
mWebView.loadUrl(getResources().getString((R.string.loaded_url)));
你能發佈您的代碼? – nurisezgin
我已添加代碼 –
您可以控制提交結果嗎?簡單地說,布爾isCommited = editor.commit() – nurisezgin