I am writing my first Android application and have some problems with passing context objects. A lot of methods / constructors seem to require the current context (activity), which causes me some problems in my action listeners. Instead of all my listeners and handlers being anonymous classes in the activity class, I created classes for every event that I would like to handle. For example, the buttonRegister button will be initialized as:
buttonRegister.setOnClickListener(new RegisterButtonClickAction());
However, I do not have access to the current context object inside my listener. I could pass the current context as a constructor parameter, but I'm not sure if this is the best choice. What is the โbest practiceโ for creating handlers / listeners in Android or for working with context objects in general?
Thanks
b3n
source
share