Asynctask不会在应该的时候调用onPostExecute方法

时间:2014-03-13 17:48:09

标签: java android android-asynctask

在Asynctask中,没有调用onPostExecute方法,但是,在doinbackground中的方法之后,Logcat都没有打印。有什么想法吗?

public class connectTask extends AsyncTask<String,String,String[]> 
{
    String FilmId, Name, Certificate, Duration, Director, Description, ReleaseDate, Cast; 
    @Override
    protected String[] doInBackground(String... params) {
        //we create a TCPClient object and
        mTcpClient = new TCPClient(new TCPClient.OnMessageReceived() {
            @Override
            //here the messageReceived method is implemented



            public void messageReceived(String message) {
                //this method calls the onProgressUpdate


                //Log.e("TCP Client", message);




                try 
                {
                    JSONObject json = new JSONObject(message);
                    FilmId = (String) json.get("FilmId");
                    Name = (String) json.get("Name");
                    Certificate = (String) json.get("Certificate");
                    Duration =(String) json.get("Duration");
                    Director = (String) json.get("Director");
                    Description = (String) json.get("Description");
                    ReleaseDate = (String) json.get("ReleaseDate");
                    Cast = (String) json.get("Cast");
                    Log.e("FilmId: ", FilmId);
                    Log.e("Name: ", Name);
                    Log.e("Cert: ", Certificate);
                    Log.e("Duration: ", Duration);
                    Log.e("Director: ", Director);
                    Log.e("Description: ", Description);
                    Log.e("ReleaseDate: ", ReleaseDate);
                    Log.e("Cast: ", Cast);
                    JSON[0] = FilmId;
                    JSON[1] = Name;                 
                    System.out.println(JSON[1]);
                    Log.e("work","work");

                } 
                catch (JSONException e)
                {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }


            }
        });


        mTcpClient.run("");
        Log.e("work","please");

        return null;
    }

    @Override
    protected void onPostExecute(String[] result) {
        // TODO Auto-generated method stub

        Log.e("work","goddammit");

        Intent FilmInfo = new Intent(FullscreenActivity.this, FilmInfo.class);
        FilmInfo.putExtra("NamePass", JSON[1]);

        FullscreenActivity.this.startActivity(FilmInfo);
        super.onPostExecute(result);
    }

    @Override
    protected void onPreExecute() {
        // TODO Auto-generated method stub
        super.onPreExecute();
    }


}

我已经检查了其他各种问题但他们没有帮助。 我使用Override / Implement方法自动在Eclipse中创建方法,以确保它们正确形成。

1 个答案:

答案 0 :(得分:0)

您应该以这种方式调用 asynctask

new AsyncTask().execute("parameter");

看看你是否这样做。