Abhi
Abhi

Reputation: 5561

I want to access inner class variable from my Outer class method in Android Activity

Is someone intelligent there who can answer this question?

I m doing some task with following code, I want to access inner class variable from outer class method.

class Outer extends Activity
{

 private Handler mHandler = new Handler();

  StopTheThread()
  {
     mHandler.removeCallbacks(mUpdateTimeTask);// this is the wat i want to do
  }

  class Inner 
  {
     final Runnable mUpdateTask = new = new Runnable() {
           public void run() {

           //Some Code Goes Here

       }
     };

     InnerClassMethod()
     {

       mHandler.removeCallbacks(mUpdateTimeTask);// This statement working fine here
      } 

  }

}

Here mUpdateTask is inner class variable which is not accessible from outer class Pleas Tell me how can i write that line

Upvotes: 1

Views: 2138

Answers (3)

Amey Haldankar
Amey Haldankar

Reputation: 2243

Create an Inner class object and then access it

Inner inner = new Inner();
inner.mUpdateTask
// use this 

OR

you can create a static mUpdateTask object and can access it using class name

Inner.mUpdateTask

Upvotes: 0

Abhinava
Abhinava

Reputation: 1030

just make the mUpdateTask static ... and call with inner class name.. Inner.mUpdateTask

also you can use getters which will be able to retrun the mUpdatetask.

if you are creating object of this Innerclass i really dont see any point of this question.. you can always call in the way Vivien described above.

Upvotes: 0

Vivien Barousse
Vivien Barousse

Reputation: 20875

You need an instance of Inner to access the mUpdateTask variable.

Something like:

Inner inner = new Inner();
inner.mUpdateTask
// ...

Upvotes: 1

Related Questions