What I’m basically trying to do is pass an instance of my Activity to another object which will build the dynamic UI.
The main reason I’m doing this is to keep the Activity class clean.
Are there any repercussions when doing this? Will it affect the garbage collection and cause memory leaks?
Here is an example of what I’m doing:
Activity:
/* uses the instance of the Activity to build Views which are loaded from XML files (for non technical users to add content */
ContentHelper ch = new ContentHelper(MyActivity.this);
Should I keep the dynamic View building within the Activity, or is it alright to pass the instance to other classes to do this?
If I keep it in the Activity, it just feels bloated to me and much harder to manage.
In my opinion it is not a good idea to pass the ACTIVITY somewhere – actually I’m not sure whether this will do anything at all.
What you can do is:
1 – You can create your own class, extending View class, build your UI there.
What you have to pass to that class is your activity context!
for example:
in the Activity that uses you ‘UI class’
2 – Then you can create an instance of your custom_UI_builder class in your Activity.
I’m not sure if this will have any unwanted effects on memory load.
Hope it will work!