dinesh707
dinesh707

Reputation: 12582

How to stop calling the onDraw() function on a View?

Im clearing up the bitmaps i load in one activity before i more into the other activity.

eg:

pic1 = null;
System.gc();
nextActivityIntent = new Intent(ThisActivity,NextActivity.class);
ThisActivity.startActivityForResult(nextActivityIntent,123);    

But the problem is system calls onDraw some times after i call "pic1=null". When it happens the application crashes with pointing a NullPoint Exception.

Cab any one suggest me how to stop calling onDraw() after setting the "pic1=null". Can i use synchornized to make this happen.

Upvotes: 0

Views: 3535

Answers (1)

Aleadam
Aleadam

Reputation: 40391

You can try view.setWillNotDraw(true); (link here), but I'm not sure it will prevent it.

On a side note, if your first activity will finish, there is no need to set the bitmap to null nor to call System.gc();. The bitmaps will be recovered anyway after the activity is destroyed.

If for some reason you still want to do it, you should do that inside the onDestroy() callback to avoid any drawing issues. Check the Activity lifecycle for more details.

Upvotes: 1

Related Questions