Android - Set Content View
I have a class extends View named GameView. In MainActivity I put it as contentView: if(Const.gameView == null){ Const.gameView = new GameView(this); Const.game
Solution 1:
try this...
if(Const.gameView == null){
Const.gameView = new GameView(this);
Const.gameView.setViews(Const.chickenArr,Const.chickenViewArr,message,score_message , this.importantMessage , this.showTimerMessage);
setContentView(Const.gameView);
} else {
ViewParent parent = Const.gameView.getParent();
if(parent != null && parentinstanceof ViewGroup) {
ViewGroup viewGroup = (ViewGroup)parent;
viewGroup.removeView(Const.gameView);
}
setContentView(Const.gameView);
}
and I observed that you are maintaining static references to Views in Const class. I suggest you that don't maintain static reference for Views as Context is associated with every View and thus leads to leakage of Context...
Solution 2:
Solution 3:
You can't use the same view in multiple activities. Instead you should create a new instance of the view
likeeverytime you have tocreatenew instance
Const.gameView =new GameView(this);
Post a Comment for "Android - Set Content View"