0

您好我正在尝试开发一个可以删除浏览器历史记录(内置或默认)的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)
4

1 回答 1

0

还有一件事发生了变化:

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

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

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

于 2013-07-03T12:09:34.447 回答