AsyncTask onPostExecute - 新的意图错误

时间:2014-04-29 04:22:22

标签: android android-intent android-asynctask

我在AsyncTask类中有这个代码:

    protected void onPostExecute(Integer result) 
    {
        if (result == 1)
        {
            try {
                Global.mmOutStream.write(99);
            } catch (IOException e) { }

            Intent intentTrashcanLocation = new Intent(TrashcanLocationActivity.this, TrashcanLocationActivity.class);     
            startActivity(intentTrashcanLocation);
        }

    }

这让我在" Intent"行:

  • 行断点:TrashcanOnWayActiity$waitarrival [line:53] - onPostExecute(Integer)
  • 在范围
  • 中无法访问类型TrashcanLocationActivity的封闭实例

我想要做的是基本上每当我异步获得某些输入时显示下一页。我无法解决这个问题。任何帮助将非常感谢!

3 个答案:

答案 0 :(得分:2)

您正在使用相同的课程

Intent intentTrashcanLocation = new Intent(TrashcanLocationActivity.this,
                                           TrashcanLocationActivity.class);     
startActivity(intentTrashcanLocation);

应该是一致的

Intent intentTrashcanLocation = new Intent(TrashcanLocationActivity.this,
                                           TrashcandetailActivity.class);     
startActivity(intentTrashcanLocation);

答案 1 :(得分:0)

试试这个,

        @Override
            protected void onPostExecute(Void result) 
           {
               super.onPostExecute(result);
               if (result == 1)
               {
                try {
                    Global.mmOutStream.write(99);
                    } catch (IOException e) { }

               Intent intent = new Intent(TrashcanLocationActivity.this, NextActivity.class); 
               getApplicationContext().startActivity(intent);
              }
           }

答案 2 :(得分:0)

您的代码没问题,但您再次调用相同的活动

 Intent intentTrashcanLocation = new Intent(TrashcanLocationActivity.this, TrashcanLocationActivity.class);     
            startActivity(intentTrashcanLocation);

TrashcanLocationActivity.class替换为您要调用的活动.class