fix crash when enter foreground.