This is a question, I'm just not quite sure about:
Every Android development tutorial you find, will put all of the code simply into the
MainActivity class (or some other class, that inherits from an
But what if you want to put code into your own classes? How do you best access certain Features?
Example for illustration:
I have created a
NetworkManager class, that should handle all my connections for the app. Now I need for example the WifiManager in this class. In my
MainActivity I would simply get it by using:
To access it in my custom class - as far as I know, at least - I would need either a reference to my
MainActivity or to the feature (in this cases the WifiManager) I need, by passing it into the instantiation.
Which is the better way? Are both wrong/right? Passing the main reference around to each class instance of any custom class seems a bit weird to me...