First of all, based on the implementation of your Activity, you have missed a few important things regarding Activities.
1. Only use static inner classes or stand alone classes for AsyncTasks: see Background task, progress dialog, orientation change - is there any 100% working solution?
Important is this:
Step #2: Have the AsyncTask hold onto the Activity via a data member, set via the constructor and a setter.
Step #5: In onCreate(), if getLastNonConfigurationInstance() is not null, cast it to your AsyncTask class and call your setter to associate your new activity with the task.
You'll notice that you will have to register and deregister your components based on the life cycle methods of Android. This is important to know, always follow the Android life cycle!
Remembering this will always lead you to the right answers regarding decoupling the Android way.
2. Use data holding classes, when needed.
This here doesn't really belong inside an Activity:
// Stores the fetched dataMap
ArrayList<HashMap<String, String>> arrayList;
When your Activity gets destroyed, e.g. during a configuration change, all your data is gone and you need to load everything again.
Accessing and storing your data can be done in many different ways: http://developer.android.com/guide/faq/framework.html#3
In your case this could be applicable:
A public static field/method
An alternate way to make data accessible across Activities/Services is to use public static fields and/or methods.
You can access these static fields from any other class in your
application. To share an object, the activity which creates your
object sets a static field to point to this object and any other
activity that wants to use this object just accesses this static
field.
Also think about storing your data insida a DB or by other means, so even after your App gets destroyed, your data isn't gone.
3. Communication with your Activity can be done like this: http://developer.android.com/guide/components/fragments.html#CommunicatingWithActivity
Use it for your Views and View Listeners in the same way. Have a component managing your Views (like a Fragment does), register it to your Activity, use it, deregister it when not needed or when the life cycle calls for it.
Like said in 1., the Android life cycle is the key to everything.
4. Dependency Injection is a very important topic and you can either use a framework for it (like Dagger 2 or RoboGuice) or do it your own way. Make sure your Injector knows the dependencies (like which Buttons need which ClickListeners and Information or which data your Adapter needs) and bind them together. When always considering the life cycle, you will see which interfaces and which methods you need and when to invoke them.
5. Don't worry about the amount of lines of code. If your design is consistent and makes sense, you won't be having readability problems even with 500 lines. Btw. when properly documenting your code, it gets easily above 150 lines of codes. So, again to worry about that.
If you have any specific questions about implementation details, ask a specific question or else you get a bloated answer.
C++
typefriend
or something similar so I can only pass pass the class objectMainActivity.this
and be done. – OmidyarString
) are perfectly okay. Other huge classes probably have too many responsibilities. Each class should do one thing to one other thing. – Estivatenew Bob().getSomething()
. I was writing a simple example so that people don't have to read so many lines to get the gist. Fixed! – OmidyarMainActivity
is abstracting exactly what it's supposed to abstract, and as far as I can tell sticks toOOP
. I believe that conceptually it wouldn't make sense to split these. I am simply looking for an implementation that allow me to implement this in a structure that maintains these relations but to keep code manageable. – Omidyar