android - How to reference the current or main activity from another class -


i find myself needing access methods require referencing activity. example, use getwindowmanager, need access activity. code using these methods in other class has no reference activity. until now, i've either stored reference main activity or passed context of activity class. there better way this?

passing context better way refrence activity.

you can pass context class.

in activity ::

anotherclass obj  = new anotherclass(this); 

in class

class anotherclass{  public anotherclass(context context){      }  } 

Comments

Popular posts from this blog

Glib GIOChannel -

delphi - When I encode/decode SMS PDU (GSM 7 Bit) user data, do I need prepend the UDH first? -

python - Obscure curses error message when creating a sub window -