You can change your code as follows:
static Handler handler = new Handler() { MainActivity mActivity; @Override public void handleMessage(Message msg) { //TODO: Handle different types of messages if(mActivity != null) { mActivity.mCamera.takePicture(null, null, mActivity); } } }; void MainActivity::onCreate(Bundle savedState) { ... handler.mActivity = this; } void MainActivity::onDestroy() { ... handler.mActivity = null; }
Alexander Kulyakhtin
source share