Working With A Non-activity Class, Which Should Be Able To Handle The Instance Variable Of The Calling Activity
I have two activities A and B, and a non activity class C. To use the methods of C, I create an instance c of C from the currently running activity (say A is in the foreground, and
Solution 1:
Even though a but vague, your Class C seems to be a helper class. Now, since you want to access instance variables (and possibly other information) in your C class, you need to pass them manually. Depending on what you are passing, it can be provided to Class C either in its constructor or via instance methods of the Class C itself.
For eg: based on the last statement of your question you can pass a ViewGroup
reference from your activity to Class C via something like this:
public void initLayout(ViewGroup parent) {
// Hide/unhide/perform actions/etc based on current activity needs
}
Similarly, you can also pass an enum
value to Class C to differentiate between your activities in Class C. For a Class C to activity communication, you can look at interface
in Java. Hope this helps.
Post a Comment for "Working With A Non-activity Class, Which Should Be Able To Handle The Instance Variable Of The Calling Activity"