Passing Activity to non-activity object properly
- by rayman
In my app ive got a non-activity object which it's role is being a manager class.
many times i need to pass "source activity" to methods as parameter to that manager class in order to make some operations on that activity.
for exaple let's assume we have MyActivity which gotta do some toast.
so i have this manager class called MyManager, and i have this method in it
raiseToast(Activity sourceActivity) {
Toast.makeText(sourceActivity, demo, Toast.LENGTH_LONG).show();
}
and from Myactivity class we calling that method this way:
MyManager manager=new MyManager();
manager.raitetoast(MyActivity.this);
it works fine.
what I'm asking here, is this a proper way to pass an Activity as parameter to a non-activity object?
I'm having a memory leaks on real device(not the emulator), I wonder if this could also causing any reason for that?
Thanks Idan.