开发者

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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜