且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

为什么canvas = null在我的情况下?

更新时间:2023-01-09 22:01:12

SurfaceView.getHolder()



onCreate()方法中时,
无法保持有效值。它还没有在那个运行时初始化。



活动有其他方法





can not hold a valid value while you are still in the onCreate() method. It''s not yet initialized at that runtime.

Activity has other methods

protected void onResume(); // before Activity run
protected void onPause(); // after Activity run





这是与 SurfaceView 互动的更好地方。



请同时阅读有关这些生命周期控制方法的文档:



活动 [ ^ ] @Android Documentation



That''s a better place to interact with the SurfaceView.

Please also read in the documentation about these lifecycle controling methods:

Activity[^] @ Android Documentation