Passing Activity to non-activity object properly

Posted by rayman on Stack Overflow See other posts from Stack Overflow or by rayman
Published on 2010-02-12T16:00:53Z Indexed on 2010/05/17 12:30 UTC
Read the original article Hit count: 377

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.

© Stack Overflow or respective owner

Related posts about android

Related posts about android-emulator