我有5秒后完成TestActivity的代码:
package com.sda.sqlite;
import java.util.Timer;
import java.util.TimerTask;
import android.app.Activity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.webkit.WebView;
import android.widget.Toast;
public class TestingActivity extends Activity {
WebView view;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
view=(WebView)findViewById(R.id.webView1);
view.loadUrl("http://www.google.com");
Timer timer=new Timer();
timer.schedule(new TimerTask(){
@Override
public void run() {
// TODO Auto-generated method stub
TestingActivity.this.finish();
}
}, 5000);
}
}
但TestingActivity不会在5秒内关闭。如果我删除Google的加载,则活动成功关闭。我哪里弄错了?
答案 0 :(得分:0)
在TestActivity上调用finish()之前尝试在WebView上调用stopLoading()方法
@Override
public void run() {
view.stopLoading();
TestingActivity.this.finish();
}