Know Your Context
As your app grows, you will start having classes that are not Android components and do not have direct access to some Context. Instead, they will be talking with your Web services, or storing things in a local database, or performing any number of other tasks that are important for your app.
In an ideal world, few of those classes will need a Context. For those that do, you will need to decide what Context they will use:
- Do they take a
Contextas a function parameter for a particular operation, so the caller chooses theContext? - Do they take a
Contextas a constructor parameter, so the choice ofContexthas to take into account how long this object is needed? - Do they do something more elaborate, such as use dependency inversion?
Prev Table of Contents Next
This book is licensed under the Creative Commons Attribution-ShareAlike 4.0 International license.