0

我有一个在 AsyncTask 完成后启动的服务。但是,当我去管理模拟器上正在运行的应用程序时,它不存在。这是我的 UI 线程代码:

public void onClick(View v) {
    // TODO Auto-generated method stub
    if (v.getId() == R.id.button1) {
        if (rBoot.isChecked()) {
            registerReceiver(new BootReceiver(), filter);
        }

        if (cb.isChecked())
            sent.putInt("progress", -10);
        else
            sent.putInt("progress", sb.getProgress());

        prog.show();
        new ProgressUpdate().execute(0);

    }

    if (v.getId() == R.id.button2) {
        stopService(i);
    }
}

和异步任务:

private class ProgressUpdate extends AsyncTask<Integer, String, String> {

    @Override
    protected String doInBackground(Integer... params) {
        // TODO Auto-generated method stub

        for (int i = 0; i <= 100; i++) {
            try {
                Thread.sleep((long) 31.4);
                progress = i;
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            if (progress == 100) {
                prog.dismiss();
            }
        }

        return "done";
    }

    @Override
    protected void onPostExecute(String result) {
        // TODO Auto-generated method stub
        super.onPostExecute(result);
        startService(new Intent(Activity.this, Service.class)
                .putExtra("bun", sent));
    }
}

对话框显示然后关闭,但服务永远不会启动。

4

0 回答 0