[Q] Access variables in an outer class

Search This thread

vin-ivar

Senior Member
Mar 4, 2011
129
58
Pune
Hullo, you lot. I was working on my own xposed module - and I had a bit of a question. Assuming I'm hooking into a function that's a member of a nested class, how do I refer to objects in the outer class? Here's what I'm trying to hook into - initContentView is a member function of the class ActionPopupWindow, which is inside the outer class Editor. I'm trying to access mTextView - a TextView defined within Editor, not ActionPopupWindow.

Any suggestions? Cheers :)
 

Tungstwenty

Senior Member
Nov 1, 2011
1,830
4,512
Hullo, you lot. I was working on my own xposed module - and I had a bit of a question. Assuming I'm hooking into a function that's a member of a nested class, how do I refer to objects in the outer class? Here's what I'm trying to hook into - initContentView is a member function of the class ActionPopupWindow, which is inside the outer class Editor. I'm trying to access mTextView - a TextView defined within Editor, not ActionPopupWindow.

Any suggestions? Cheers :)
Use XposedHelpers.getSurroundingThis(...), something like:
Code:
Object outerObject = XposedHelpers.getSurroundingThis(param.thisObject);
Object fieldValue = XposedHelpers.getObjectField(outerObject, "mTextView");
...

However, for the specific case you mention I don't think this is what you need. mTextView isn't defined on the Editor class but rather on PinnedPopupWindow, which is also an inner class and a superclass of ActionPopupWindow.
getObjectField() is aware of fields on superclasses and will fetch it for you just by using:
Code:
XposedHelpers.getObjectField(param.thisObject, "mTextView");
 
  • Like
Reactions: lj3lj3 and vin-ivar

vin-ivar

Senior Member
Mar 4, 2011
129
58
Pune
This is exactly what I was looking for, thank you! Although you were wrong about the inherited part; mTextView is a member of Editor.

I'm curious - where did you read all this? There doesn't seem to be very cohesive documentation on the wiki :/

Thanks again! :)
 

GermainZ

Inactive Recognized Developer / Retired Forum Mod
Aug 3, 2012
6,170
8,805
This is exactly what I was looking for, thank you! Although you were wrong about the inherited part; mTextView is a member of Editor.

I'm curious - where did you read all this? There doesn't seem to be very cohesive documentation on the wiki :/

Thanks again! :)
You can check the helper classes (e.g. XposedHelpers) and read the Java docs.
 

Tungstwenty

Senior Member
Nov 1, 2011
1,830
4,512
This is exactly what I was looking for, thank you! Although you were wrong about the inherited part; mTextView is a member of Editor.

I'm curious - where did you read all this? There doesn't seem to be very cohesive documentation on the wiki :/

Thanks again! :)
There is a wiki page about the helpers, but it doesn't cover them all. The best thing is to check the existing methods and read the javadocs, as mentioned by GermainZ.
 

Top Liked Posts

  • There are no posts matching your filters.
  • 2
    Hullo, you lot. I was working on my own xposed module - and I had a bit of a question. Assuming I'm hooking into a function that's a member of a nested class, how do I refer to objects in the outer class? Here's what I'm trying to hook into - initContentView is a member function of the class ActionPopupWindow, which is inside the outer class Editor. I'm trying to access mTextView - a TextView defined within Editor, not ActionPopupWindow.

    Any suggestions? Cheers :)
    Use XposedHelpers.getSurroundingThis(...), something like:
    Code:
    Object outerObject = XposedHelpers.getSurroundingThis(param.thisObject);
    Object fieldValue = XposedHelpers.getObjectField(outerObject, "mTextView");
    ...

    However, for the specific case you mention I don't think this is what you need. mTextView isn't defined on the Editor class but rather on PinnedPopupWindow, which is also an inner class and a superclass of ActionPopupWindow.
    getObjectField() is aware of fields on superclasses and will fetch it for you just by using:
    Code:
    XposedHelpers.getObjectField(param.thisObject, "mTextView");