Why onSurfaceTextureDestroyed
isn't called in Android 7, 8 when activity becomes invisible (onPause
, onStop
are called)?
To fix issue with TextureView
frame filling when Camera Preview is bigger or smaller than TextureView's
size I use TextureView's
SurfaceTexture.setDefaultBufferSize(cameraWidth, cameraHeight)
but after activity becomes invisible (onPause
, onStop
) and onSurfaceTextureDestroyed
isn't called I try to get back to activity (onResume
, onStart
) frame doesn't fit TextureView size anymore and I try to call SurfaceTexture.setDefaultBufferSize(cameraWidth, cameraHeight)
again but it doesn't effect anything (frames won't fill full view) until I call this method later:
public void onStart() {
mTextureView.postDelayed(() -> {
mTextureView.getSurfaceTexture().setDefaultBufferSize(cameraWidth, cameraHeight);
}, 2000);
}
so onSurfaceTextureDestroyed
isn't called during onPause, onStop
and onSurfaceTextureAvailable
is called only once after onCreate, onStart, onResume but isn't called after activity reopen (onPause, onStop, onStart, onResume) because texture wasn't destroyed....
mTextureView.setSurfaceTextureListener(new TextureView.SurfaceTextureListener() {
@Override
public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
// is called only once, isn't called after reopening activity
Log.i(TAG, "mTextureView onSurfaceTextureAvailable");
surface.setDefaultBufferSize(cameraWidth, cameraHeight)
}
@Override
public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
// isn't called on Android 7, 8
Log.i(TAG, "mTextureView onSurfaceTextureDestroyed");
return true;
}
...
});