Xin lỗi vì câu hỏi đơn giản, tôi là người phát triển java và android hoàn toàn mới bắt đầu. Làm thế nào tôi có thể có được thể hiện của hoạt động trong setCameraDisplayOrientation khi surfaceChanged được gọi là?Lấy ví dụ hoạt động
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);
....
}
}
}
Tại sao bạn cần trường hợp của nó. Phương pháp ghi đè của nó, nó sẽ có một số bối cảnh hoạt động. Nhưng vẫn còn nếu bạn muốn, hãy thử sử dụng 'MyActivity.this' – Rajkiran
Tôi sử dụng' this' nhưng chương trình sụp đổ khi surfaceChanged gọi. Được. Tôi sẽ kiểm tra lại lý do tại sao chương trình bị lỗi. Tôi cần trường hợp này để gọi phương thức của nó trong ngữ cảnh: 'activity.getWindowManager(). GetDefaultDisplay() \t .getRotation()' – psct