gpt4 book ai didi

Android 开发 - 新 Activity 打开太快

转载 作者:搜寻专家 更新时间:2023-11-01 09:36:47 25 4
gpt4 key购买 nike

我正在开发一款可以拍照然后切换到新 Activity 的应用。这是执行此操作的函数:

public void takePhoto(View view){
final int REQUEST_IMAGE_CAPTURE = 1;

// open camera
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if(takePictureIntent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
}

// open "Enter Info" screen
startActivity(new Intent(MainActivity.this, EnterInfoActivity.class));
}

但是,“输入信息” Activity 在相机之前打开。我希望在开始新 Activity 之前打开相机。按“后退”将我带到相机,这对我来说意味着相机确实加载,但 Activity 被赋予更高的优先级。

最佳答案

private void captureImage() {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE);

intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);

// start the image capture Intent
startActivityForResult(intent, CAMERA_CAPTURE_IMAGE_REQUEST_CODE);
}

in onActivityResult Open Your Second Activity

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// if the result is capturing Image
if (requestCode == CAMERA_CAPTURE_IMAGE_REQUEST_CODE) {
if (resultCode == RESULT_OK) {
// successfully captured the image
// display it in image view
previewCapturedImage();
} else if (resultCode == RESULT_CANCELED) {
// user cancelled Image capture
Toast.makeText(getApplicationContext(),
"User cancelled image capture", Toast.LENGTH_SHORT)
.show();
} else {
// failed to capture image
Toast.makeText(getApplicationContext(),
"Sorry! Failed to capture image", Toast.LENGTH_SHORT)
.show();
}
}
}

喵信息看这个,http://www.androidhive.info/2013/09/android-working-with-camera-api/

关于Android 开发 - 新 Activity 打开太快,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42491372/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com