albnok
albnok

Reputation: 530

setting an onClickListener statically, memory leak?

I am thinking of making a reusable function to make views clickable to dismiss - in this example RelativeLayoutAO is the background.

    final RelativeLayout rlAO = (RelativeLayout) findViewById(R.id.RelativeLayoutAO);
    Utility.setOnClickFinish(rlAO);

And then in the Utility class:

public class Utility {
    public static void setOnClickFinish(View view) {
        view.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View clickedView) {
            ((Activity) clickedView.getContext()).finish();
        }
    });
}
}

Would this cause a memory leak?

Upvotes: 1

Views: 595

Answers (1)

glorifiedHacker
glorifiedHacker

Reputation: 6420

No, this should not cause a memory leak.

Based on the title of your question, I think it's possible that you are misunderstanding the implications of the static keyword here. You aren't setting anything "statically". The fact that setOnClickFinish() is marked as static simply means that it is a class method.

Upvotes: 2

Related Questions