助けてください、私はすでにインターネット全体を検索しました。前のページに移動するのではなく、[戻る] ボタンを押してプログラムを閉じるのはなぜですか? その理由はwebview.canGoBack()
.
public class MainActivity extends Activity {
WebView webview;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
webview = (WebView) findViewById(R.id.webView1);
new ParseMyPageTask()
.execute("https://mysite.com/forumdisplay.php?f=36&styleid=35");
webview.setWebViewClient(new ForumWebViewClient());
}
class ParseMyPageTask extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... params) {
Document doc = null;
String htmltext = "";
try {
doc = Jsoup.connect(params[0]).get();
Elements body = doc.select("ul.forumbits, ul#stickies, ul#threads, ol#posts");
htmltext = body.html();
} catch (IOException e) {
e.printStackTrace();
}
return htmltext;
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
webview.getSettings().setUseWideViewPort(true);
webview.setInitialScale(0);
webview.loadDataWithBaseURL(null, "result", "text/html", "UTF-8", null);
}
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK) && webview.canGoBack()) {
webview.goBack();
return true;
}
return super.onKeyDown(keyCode, event);
}
private class ForumWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
new ParseMyPageTask().execute("https://mysite.com/" + url + "&styleid=35");
return true;
}
}
}
ここのどこかが原因だと思います:
private class ForumWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
new ParseMyPageTask().execute("https://mysite.com/" + url + "&styleid=35");
return true;
}
}
の結果
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK) && webview.canGoBack()) {
if (isDebug) {
Log.v(TAG, "BackButton canGoBack. " + event);
}
webview.goBack();
return true;
}
if (isDebug) {
Log.v(TAG, "BackButton pressed. " + event);
}
return super.onKeyDown(keyCode, event);
}
は
07-29 21:20:42.711: I/webclipboard(9044): clipservice: android.sec.clipboard.ClipboardExManager@421e3cf0
07-29 21:20:42.806: E/webview(9044): registerForStylusPenEvent onAttachedToWindow
07-29 21:20:42.806: E/webview(9044): registerForStylusPenEvent START
07-29 21:20:42.826: E/webview(9044): registerForStylusPenEvent END
07-29 21:20:43.301: D/libEGL(9044): loaded /system/lib/egl/libEGL_mali.so
07-29 21:20:43.351: D/libEGL(9044): loaded /system/lib/egl/libGLESv1_CM_mali.so
07-29 21:20:43.356: D/libEGL(9044): loaded /system/lib/egl/libGLESv2_mali.so
07-29 21:20:43.366: D/(9044): Device driver API match
07-29 21:20:43.366: D/(9044): Device driver API version: 10
07-29 21:20:43.366: D/(9044): User space API version: 10
07-29 21:20:43.366: D/(9044): mali: REVISION=Linux-r2p4-02rel0 BUILD_DATE=Thu Oct 25 08:43:05 KST 2012
07-29 21:20:43.461: D/OpenGLRenderer(9044): Enabling debug mode 0
07-29 21:20:43.481: D/WebView(9044): onSizeChanged - w:800 h:1196
07-29 21:20:43.501: I/Choreographer(9044): Skipped 39 frames! The application may be doing too much work on its main thread.
07-29 21:20:43.781: V/webkit(9044): BrowserFrame constructor: this=Handler (android.webkit.BrowserFrame) {421dddc8}
07-29 21:20:43.796: D/dalvikvm(9044): GC_CONCURRENT freed 258K, 7% free 12340K/13191K, paused 111ms+70ms, total 272ms
07-29 21:20:44.106: D/TilesManager(9044): new EGLContext from framework: 5a920fb8
07-29 21:20:44.106: D/GLWebViewState(9044): Reinit shader
07-29 21:20:44.191: D/GLWebViewState(9044): Reinit transferQueue
07-29 21:20:45.421: D/dalvikvm(9044): GC_CONCURRENT freed 267K, 7% free 12529K/13447K, paused 11ms+1ms, total 28ms
07-29 21:20:45.661: D/dalvikvm(9044): GC_CONCURRENT freed 455K, 9% free 12532K/13639K, paused 12ms+12ms, total 42ms
07-29 21:20:45.856: D/dalvikvm(9044): GC_CONCURRENT freed 112K, 7% free 12803K/13639K, paused 11ms+2ms, total 30ms
07-29 21:20:45.946: I/dalvikvm(9044): Total arena pages for JIT: 11
07-29 21:20:45.966: D/dalvikvm(9044): GC_CONCURRENT freed 361K, 7% free 12938K/13895K, paused 2ms+9ms, total 33ms
07-29 21:20:46.846: I/GATE(9044): <GATE-M>DEV_ACTION_COMPLETED</GATE-M>
07-29 21:20:49.821: V/WebViewInputDispatcher(9044): blockWebkitDraw
07-29 21:20:49.821: V/WebViewInputDispatcher(9044): blockWebkitDraw lockedfalse
07-29 21:20:49.826: V/webview(9044): singleCursorHandlerTouchEvent -getEditableSupport FASLE
07-29 21:20:50.126: D/webview(9044): blockWebkitViewMessage= false
07-29 21:20:50.146: D/WebCore(9044): uiOverrideUrlLoading: shouldOverrideUrlLoading() returnstrue
07-29 21:20:51.591: D/dalvikvm(9044): GC_CONCURRENT freed 535K, 9% free 12840K/13959K, paused 14ms+2ms, total 35ms
07-29 21:20:51.616: D/dalvikvm(9044): GC_FOR_ALLOC freed 40K, 8% free 12850K/13959K, paused 15ms, total 15ms
07-29 21:20:51.616: I/dalvikvm-heap(9044): Grow heap (frag case) to 13.208MB for 131088-byte allocation
07-29 21:20:51.631: D/dalvikvm(9044): GC_FOR_ALLOC freed 0K, 9% free 12978K/14151K, paused 15ms, total 15ms
07-29 21:20:51.646: D/dalvikvm(9044): GC_FOR_ALLOC freed 0K, 9% free 12978K/14151K, paused 14ms, total 14ms
07-29 21:20:51.646: I/dalvikvm-heap(9044): Grow heap (frag case) to 13.333MB for 131088-byte allocation
07-29 21:20:51.661: D/dalvikvm(9044): GC_FOR_ALLOC freed 0K, 9% free 13106K/14343K, paused 15ms, total 15ms
07-29 21:20:51.681: D/dalvikvm(9044): GC_FOR_ALLOC freed 411K, 10% free 12969K/14343K, paused 15ms, total 15ms
07-29 21:20:51.701: I/dalvikvm(9044): Total arena pages for JIT: 12
07-29 21:20:51.761: D/dalvikvm(9044): GC_CONCURRENT freed 264K, 9% free 13088K/14343K, paused 12ms+12ms, total 38ms
07-29 21:20:51.856: D/dalvikvm(9044): GC_CONCURRENT freed 284K, 9% free 13187K/14343K, paused 12ms+1ms, total 29ms
07-29 21:20:51.946: D/dalvikvm(9044): GC_CONCURRENT freed 292K, 8% free 13293K/14343K, paused 12ms+12ms, total 41ms
07-29 21:20:52.056: D/dalvikvm(9044): GC_CONCURRENT freed 532K, 8% free 13201K/14343K, paused 12ms+11ms, total 42ms
07-29 21:20:52.116: D/dalvikvm(9044): GC_FOR_ALLOC freed 665K, 10% free 12919K/14343K, paused 15ms, total 15ms
07-29 21:20:52.201: I/GATE(9044): <GATE-M>DEV_ACTION_COMPLETED</GATE-M>
07-29 21:20:54.116: V/myLogs(9044): BackButton pressed. KeyEvent { action=ACTION_DOWN, keyCode=KEYCODE_BACK, scanCode=158, metaState=0, flags=0x8, repeatCount=0, eventTime=163583381, downTime=163583381, deviceId=4, source=0x101 }
07-29 21:20:54.596: W/IInputConnectionWrapper(9044): showStatusIcon on inactive InputConnection
07-29 21:20:54.596: E/webview(9044): removeForStylusPenEvent onDetachedFromWindow
07-29 21:20:54.596: E/webview(9044): removeForStylusPenEvent START
07-29 21:20:54.596: E/webview(9044): removeForStylusPenEvent END
次のコードの結果は同じです:
@Override
public void onBackPressed(){
if (webview.canGoBack()) {
webview.goBack();
if (isDebug) {
Log.v(TAG, "goBack");
}
return;
}
if (isDebug) {
Log.v(TAG, "onBackPressed");
}
super.onBackPressed();
}