Java的Andr​​oid的AsyncTask的 - 什么时候AsyncTask的停止运行? [英] Java Android AsyncTask - When does AsyncTask stop running?

查看:94
本文介绍了Java的Andr​​oid的AsyncTask的 - 什么时候AsyncTask的停止运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个运行和它的工作,并完成一个AsyncTask的。 onPostExecute做什么它应该做的,一切都很好。但任务仍然是在Eclipse调试窗口中运行。我每次运行任务,我得到一个新的。所以,它的我猜的任务不是重新使用。

I have a AsyncTask that runs and does its job and completes. onPostExecute does what its supposed to do and all is good. BUT the task is still running on the debug window in Eclipse. Every time I run the task I get a new one. So its not re-using the task I guess.

有没有人见过这个?

推荐答案

我写了这个测试应用程序尝试AsyncTask的。它运行5后台任务,然后必须重用他们。我只是想知道,这是不错的方法我一直没能找到解决这一问题的任何引用。我想知道为什么5个任务?难道他们释放内存,他们正在采取任何其他?我早就把这个注释,但没有似乎让code剪

I wrote this test app to try the asynctask. it runs 5 background tasks, and then must reuse them. I would just like to know that this is OK as I have not been able to find any reference to this concern. I would like to know why 5 tasks? Do they release memory and whatever else they are taking? I would have put this in a comment but didnt seem to allow code snips

    package com.mvw.tas;

import java.io.IOException;

import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

public class TestAsync extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);


        Button btnD = (Button)findViewById(R.id.Btn01);

        btnD.setOnClickListener(new Button.OnClickListener() {

            @Override
            public void onClick(View v) {
                new gback().execute( "");
            }
        });

    }

    ////////////////////////////////////////
    public class gback extends AsyncTask<String, Void, IOException> {
        //@Override
        protected IOException doInBackground(String... params) {
            Log.d( "ASTEST", "Running background");
            return null;

        }

        @Override
        protected void onPostExecute(IOException result) {
            Log.d( "ASTEST", "Post Exec");


        }

        @Override
        protected void onPreExecute() {

            Log.d( "ASTEST", "PRE Exec");;
        }

    }

}

和XML

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hello"
    />



<Button android:text="Test AysncTask" android:id="@+id/Btn01" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
</LinearLayout>

这篇关于Java的Andr​​oid的AsyncTask的 - 什么时候AsyncTask的停止运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆