Reputation: 856
I am trying to implement a solution that I found HERE but after I hit capture, the back button doesn't finish the activity. Is there a way to call
finish();
when the back button is pressed within the function
private void capture() {
mCamera.takePicture(null, null, null, new Camera.PictureCallback() {
final float bearing = degree;
@Override
public void onPictureTaken(byte[] data, Camera camera) {
latitude = mGpsLocationTracker.getLatitude();
longitude = mGpsLocationTracker.getLongitude();
Toast.makeText(getApplicationContext(), "Picture Taken",
Toast.LENGTH_SHORT).show();
Toast.makeText(getApplicationContext(), "" +
latitude + ", " + longitude, Toast.LENGTH_SHORT).show();
Toast.makeText(getApplicationContext(), "" + bearing, Toast.LENGTH_SHORT).show();
Intent intent = new Intent();
intent.putExtra("image_arr", data);
setResult(RESULT_OK, intent);
camera.stopPreview();
if (camera != null) {
camera.release();
mCamera = null;
}
finish();
}
});
}
@Override
public void onBackPressed() {
super.onBackPressed();
finish();
}
Upvotes: 1
Views: 236
Reputation: 2128
Ok instead of doying finish();
try to make an intent to the desired activity
:
@Override
public void onBackPressed() {
super.onBackPressed();
startActivity(new Intent(YourActivity, DesiredActivity));
finish();
}
Upvotes: 1
Reputation: 1061
Try Overriding onKey method in your activity class
@Override
public boolean onKey(View v, int keyCode, KeyEvent event)
{ if (event.getAction() == KeyEvent.ACTION_UP)
{ finish();
}
return false;
};
Upvotes: 0