I’m making an Android app and have it structured as a simple multi-activity app. I want to add a navigation drawer to it, and it looks like I will need to completely restructure the app and load everything as fragments. (http://developer.android.com/training/implementing-navigation/nav-drawer.html)
How should I begin performing this “movement” of code? Should I completely copy and paste my class variables and functions into a giant file? This definitely feels like it would be prone to bugs and errors. Perhaps there’s a method of separating the class files but still having one navigation drawer?
I have recently had to do something similar with a relatively complex app (lots of NFC + networking + custom views). I found that I ended up with a massive ~1500 line main class.
So I split up the various functional parts of the app into several classes. All of these subclass a manager superclass which I defined as having only one method: attach(). It takes an activity as an argument and stores it as a local variable. This allows the manager classes to have a reference to a context.
So now I have several manager classes all instantiated in my Main onCreate. UIManager, NfcManager, NetworkManager, etc. Each is responsible for its respective logic and is easy to modify individually without having to modify the main activity class.
2