Dưới đây là một thử nghiệm nhỏ mà tôi đã thực hiện, nơi tôi đính kèm một SurfaceTextureListener vào một TextureView trong phần onResume() của một hoạt động.SurfaceTexture có tồn tại một chu kỳ tạm dừng/tiếp tục hoạt động không?
trên tươi bắt đầu: một kết cấu bề mặt được làm sẵn ("onSurfaceTextureAvailable")
về biến đổi định hướng: như tôi mong đợi, kết cấu bề mặt bị phá hủy ("onSurfaceTextureDestroyed") và một kết cấu bề mặt sau đó được tạo sẵn ("onSurfaceTextureAvailable").
Bây giờ đây là những gì làm tôi ngạc nhiên:
- trên switch nhiệm vụ sau đó tiếp tục: kết cấu bề mặt không bị phá hủy (không "onSurfaceTextureDestroyed") và một kết cấu bề mặt không được cung cấp (no "onSurfaceTextureAvailable")
Trong những điều kiện này, tôi có đảm bảo rằng SurfaceTexture cũ là stil có hiệu lực? Làm thế nào tôi có thể chắc chắn rằng tôi thực sự biết khi SurfaceTexture của tôi có sẵn? Tại sao thay đổi định hướng lại khác với công tắc nhiệm vụ và tôi nên biết như thế nào?
public class MainActivity extends AppCompatActivity {
private final String TAG = "MainActivity";
TextureView mTextureView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mTextureView = (TextureView) findViewById(R.id.textureView);
}
@Override
public void onResume() {
super.onResume();
mTextureView.setSurfaceTextureListener(new TextureView.SurfaceTextureListener() {
@Override
public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
Log.d(TAG, "onSurfaceTextureAvailable");
}
@Override
public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {
Log.d(TAG, "onSurfaceTextureSizeChanged");
}
@Override
public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
Log.d(TAG, "onSurfaceTextureDestroyed");
return false;
}
@Override
public void onSurfaceTextureUpdated(SurfaceTexture surface) {
}
});
}
}