获取活动实例
2022-09-01 20:26:49
请原谅我简单的问题,我完全是Java和Android开发人员的初学者。如何获取 setCameraDisplay 在调用 surfaceChanged 时的活动实例?
public class MyActivity extends Activity
{
private Camera mCamera;
private CameraPreview mPreview;
public final int cameraId = 0;
public Activity activity = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
activity = this;
// Create an instance of Camera
mCamera = getCameraInstance();
// Create our Preview view and set it as the content of our activity.
mPreview = new CameraPreview(this, mCamera);
FrameLayout preview = (FrameLayout) findViewById(R.id.camera_preview);
preview.addView(mPreview);
}
public void setCameraDisplayOrientation(Activity activity,
int cameraId, android.hardware.Camera camera) {
}
public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback {
private SurfaceHolder mHolder;
private Camera mCamera;
...
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
...
setCameraDisplayOrientation(activity, cameraId, mCamera);
....
}
}
}