使用AsyncTask删除Android的内置浏览器的历史记录

时间:2013-07-03 11:26:06

标签: android browser android-asynctask

您好我正在尝试开发一个可以删除浏览器历史记录(内置或默认)的Android应用程序,到目前为止,我能够正确删除历史记录,但是当移动浏览器拥有大量历史记录时,则强制执行关闭警报框来了,我知道我正在做UI线程中的所有内容,所以我浏览了AsyncTask文章,但无法正确理解我的历史记录删除代码的位置请帮助我,提前致谢。

这是我的MainActivity

public class MainActivity extends Activity {

Button btn;
/** Called when the activity is first created. */

@Override
public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    btn = (Button) findViewById(R.id.button1);
    btn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            startActivity(new Intent(MainActivity.this,SecondClass.class));
        }
    });
}
}

这是我的SecondClass代码

public class SecondClass extends Activity {
ProgressDialog pd;
ProgressDialog progressDialog;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_second_class);

    new AsyncTask<Void, Void, Void>()
    {
        @Override
        protected void onPreExecute() {
            pd = ProgressDialog.show(this, "Loading..", "Please Wait", true,false);
        }

        @Override
        protected Void doInBackground(Void... params) {
            Browser.clearHistory(getContentResolver());
            return null;
        }

        @Override
        protected void onPostExecute(Void result) {
            pd.dismiss();
        }
    }.execute((Void[])null);
}
}

请帮助我,提前致谢

这是我的LogCat

W/ActivityManager(   61):   Force finishing activity com.example.handlerlearn/.SecondClass

W/InputManagerService(   61): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@40720228

E/WindowManager( 2089): Activity com.example.handlerlearn.SecondClass has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@40525230 that was originally added here

E/WindowManager( 2089): android.view.WindowLeaked: Activity com.example.handlerlearn.SecondClass has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@40525230 that was originally added here

E/WindowManager( 2089):     at android.view.ViewRoot.<init>(ViewRoot.java:258)

E/WindowManager( 2089):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)

E/WindowManager( 2089):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)

E/WindowManager( 2089):     at android.view.Window$LocalWindowManager.addView(Window.java:424)

1 个答案:

答案 0 :(得分:0)

还有一件事要改变:

pd = ProgressDialog.show(this, "Loading..", "Please Wait", true,false);

pd = ProgressDialog.create().show(this, "Loading..", "Please Wait", true,false);

这可能是缺少的对话框屏幕,尚未创建。