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.
精彩评论