Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/mercurial/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android java需要时间,直到应用程序从摄像头返回_Android_Android Intent_Android Activity_Parse Platform - Fatal编程技术网

Android java需要时间,直到应用程序从摄像头返回

Android java需要时间,直到应用程序从摄像头返回,android,android-intent,android-activity,parse-platform,Android,Android Intent,Android Activity,Parse Platform,我有onActivityResult函数(在拍摄完一张照片后)和在相机中运行的函数。也就是说,我没有看到ProgressDialog,因为它是在摄影机上运行的,并且加载了很多时间。 我如何才能做到这一点?首先,应用程序将从照相机意图返回,然后运行onActivityResult函数 Intent chooserIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); File f = new

我有onActivityResult函数(在拍摄完一张照片后)和在相机中运行的函数。也就是说,我没有看到ProgressDialog,因为它是在摄影机上运行的,并且加载了很多时间。 我如何才能做到这一点?首先,应用程序将从照相机意图返回,然后运行onActivityResult函数

Intent chooserIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                            File f = new File(Environment.getExternalStorageDirectory(), "POST_IMAGE.jpg");
                            chooserIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f));
                            imageToUploadUri = Uri.fromFile(f);
                            startActivityForResult(chooserIntent, 1220);
职能:

@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data)
    {
        super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == 1220 && resultCode == RESULT_OK)
    {


        final ProgressDialog mDialog = new ProgressDialog(PageAndExercise.this);
        mDialog.setMessage(getString(R.string.loading));
        mDialog.setCancelable(false);
        mDialog.show();

        Uri selectedImage = imageToUploadUri;
        getContentResolver().notifyChange(selectedImage, null);
        Bitmap reducedSizeBitmap = getBitmap(imageToUploadUri.getPath());
        if(reducedSizeBitmap != null) {



            ByteArrayOutputStream stream = new ByteArrayOutputStream();
            reducedSizeBitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
            //  bookimage.setImageBitmap(photo);
            byte[] image = stream.toByteArray();
            ParseFile file = new ParseFile("photo.jpeg", image);
            file.saveInBackground();


            ParseObject toaccept = new ParseObject("Answers");

            toaccept.put("Picture", file);


            try {
               toaccept.save();
} catch (ParseException e1) {
                    e1.printStackTrace();
                }

        } else {
            Toast.makeText(getApplicationContext(),getString(R.string.error),Toast.LENGTH_LONG).show();
        }

    }
}

mDialog.show()之后的所有内容移动到后台线程中。不要在主应用程序线程上执行磁盘I/O、数据解析等操作


然后,将
mDialog.show()
替换为
DialogFragment
,以管理您的
ProgressDialog
,从而正确处理配置更改(例如屏幕旋转)。

谢谢!但我得到错误:致命异常:AsyncTask#5 java.lang.RuntimeException:无法在未调用Looper.prepare()的线程内创建处理程序,该线程位于AlertDialog AlertDialog=alertDialog2.create()行中;alertDialog2.show()@罗恩:你的问题里没有这样的密码。如果新代码导致新崩溃,请在发布新代码和新堆栈跟踪的位置提出新问题,以便新用户可以检查新问题并给出新答案。