I have code for finishing TestActivity after 5 seconds:
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);
}
}
But TestingActivity won't close in 5 seconds. If I delete loading of Google, then Activity closes successfully. Where have I made mistake?
Try calling stopLoading() method on the WebView before calling finish() on the TestActivity
@Override
public void run() {
view.stopLoading();
TestingActivity.this.finish();
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.