Вопрос

I have this code in my AsyncTask class:

    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);
        }

    }

This gives me error at the "Intent" line:

  • line breakpoint:TrashcanOnWayActiity$waitarrival [line:53] - onPostExecute(Integer)
  • No enclosing instance of the type TrashcanLocationActivity is accessible in scope

What I want to do is basically displaying the next page whenever I get certain input asynchronously. I couldn't solve this problem. Any help will be really appreciated!

Это было полезно?

Решение

You are using the same class

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

should be something along the lines

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

Другие советы

Try this,

        @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);
              }
           }

Your code is fine, but you are calling the same Activity again

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

replace TrashcanLocationActivity.class with the activity you want to call .class

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top