After reading the the Avoiding memory leaks article by @RomainGuy I realized that my current Android application is plagued with the mistake of passing the application's main activity around. So whenever I, can I simply replace that activity parameter with Activity.getApplicationContext().
But there are certain classes in my application that still need to run methods that can only be members of the applications main activity.
Thus I was thinking of possibly using the Command Pattern to workaround this limitation.
The problem is that, if we look at that example:
public class SomeCommandExecuableOnlyByActivity implements Command
{
public void execute(Object data)
{
doIt( ((MyActivity)data).getWindow() );
}
}
I am running again into the dead end of needing the pass around the activity (this time disguised as Object
data).
How do I get out of this "chicken & the egg" situation?
Is there a better way to approach this problem?