我的应用有问题。这是我的活动TakePhotoOrUpload
public class TakePhotoOrUpload extends AppCompatActivity implements View.OnClickListener{
Button btnTakePhoto;
Button btnUploadPhoto;
Button btnViewPhotos;
Button btnLogout;
@Override
public void onClick(View v) {
if (v.getId() == R.id.btnTakePhoto) {
Intent intent = new Intent(getApplicationContext(), TakePhoto.class);
startActivity(intent);
}
if (v.getId() == R.id.btnUploadPhoto) {
Intent intent = new Intent(getApplicationContext(), UploadPhoto.class);
startActivity(intent);
}
if (v.getId() == R.id.btnViewPhotos) {
Intent intent = new Intent(getApplicationContext(), ViewPhotos.class);
startActivity(intent);
}
if (v.getId() == R.id.btnLogout) {
ParseUser.logOut();
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
startActivity(intent);
}
}
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_take_photo_or_upload);
btnTakePhoto = (Button) findViewById(R.id.btnTakePhoto);
btnUploadPhoto = (Button) findViewById(R.id.btnUploadPhoto);
btnViewPhotos = (Button) findViewById(R.id.btnViewPhotos);
btnLogout = (Button) findViewById(R.id.btnLogout);
btnTakePhoto.setOnClickListener(this);
btnUploadPhoto.setOnClickListener(this);
btnViewPhotos.setOnClickListener(this);
btnLogout.setOnClickListener(this);
}
}
然后当我点击TAKE PHOTO按钮然后打开此代码(TakePhoto活动)
public class TakePhoto extends AppCompatActivity {
RelativeLayout relativeLayout;
static final int REQUEST_TAKE_PHOTO = 1;
private void dispatchTakePictureIntent() {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
// Ensure that there's a camera activity to handle the intent
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
// Create the File where the photo should go
File photoFile = null;
try {
photoFile = createImageFile();
} catch (IOException ex) {
// Error occurred while creating the File
}
// Continue only if the File was successfully created
if (photoFile != null) {
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
Uri.fromFile(photoFile));
startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO);
}
}
}
String mCurrentPhotoPath;
private File createImageFile() throws IOException {
// Create an image file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String imageFileName = "JPEG_" + timeStamp + "_";
File storageDir = Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES);
File image = File.createTempFile(
imageFileName, /* prefix */
".jpg", /* suffix */
storageDir /* directory */
);
// Save a file: path for use with ACTION_VIEW intents
mCurrentPhotoPath = "file:" + image.getAbsolutePath();
return image;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_take_photo_or_upload);
relativeLayout = (RelativeLayout) findViewById(R.id.relativeLayout5);
dispatchTakePictureIntent();
try {
createImageFile();
} catch (IOException e) {
e.printStackTrace();
}
}
}
我的问题是,当我拍照并保存时,它会出现带按钮的活动(akePhotoOrUpload)但按钮没有响应。我必须单击手机上的后退按钮,然后活动就像刷新一样,一切正常。你能看到代码中的问题吗?感谢。