Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/390.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
Java 异步任务停止工作,在使用断点进行调试时工作-Android_Java_Android_Asynchronous_Android Asynctask_Android Camera - Fatal编程技术网

Java 异步任务停止工作,在使用断点进行调试时工作-Android

Java 异步任务停止工作,在使用断点进行调试时工作-Android,java,android,asynchronous,android-asynctask,android-camera,Java,Android,Asynchronous,Android Asynctask,Android Camera,我的异步任务正在执行繁重的图像处理,单个异步任务可以成功运行,但如果我尝试执行多个异步任务,即在第一个任务完成之前,它将停止工作。。。 虽然它在调试和插入时工作得很好,但它有断点来检查问题 我只需要在ActivityResult上有一个断点 private class ProcessVideoTask extends AsyncTask<String, Void, Void> { int goodPointsLocal; int badPointsLocal

我的异步任务正在执行繁重的图像处理,单个异步任务可以成功运行,但如果我尝试执行多个异步任务,即在第一个任务完成之前,它将停止工作。。。 虽然它在调试和插入时工作得很好,但它有断点来检查问题

我只需要在ActivityResult上有一个断点

    private class ProcessVideoTask extends AsyncTask<String, Void, Void> {

    int goodPointsLocal;
    int badPointsLocal;
    String videoFileLocal;
    ArrayList<Integer> xposLocal;
    ArrayList<Integer> yposLocal;
    ArrayList<String> markerSelectedLocal;
    int windowXxLocal;
    int windowYyLocal;

    public ProcessVideoTask(int _goodPoints, int _badPoints,
            String _videoFile, ArrayList<Integer> _xpos,
            ArrayList<Integer> _ypos, ArrayList<String> _markerSelected,
            int _windowXx, int _windowYy) {
        // TODO Auto-generated constructor stub

        goodPointsLocal = _goodPoints;
        badPointsLocal = _badPoints;
        videoFileLocal = _videoFile;
        xposLocal = _xpos;
        yposLocal = _ypos;
        markerSelectedLocal = _markerSelected;
        windowXxLocal = _windowXx;
        windowYyLocal = _windowYy;

    }

    // automatically done on worker thread (separate from UI thread)
    protected Void doInBackground(final String... args) {
        notGotoBack = false;
        String path = videoFileLocal;
        ProcessVDOToImages(path);
        try {//get frames from video and edit individually (heavy processing)
            PutMarkersOnImages(xposLocal, yposLocal, markerSelectedLocal,
                    Constants.RT_EVALUATE_TRAINING, windowXxLocal,
                    windowYyLocal);
        } catch (Exception e) {

        }

        mFilePathMarkers = ProcessImagestoVdo();//append audio to frames (heavy)
        SetAudioWithMarkerVDO(mFilePathMarkers, videoFileLocal);

        return null;
    }

    protected void onPostExecute(final Void unused) {
        File savePathWMarker = new File(Environment
                .getExternalStorageDirectory().getPath()
                + "/HumanFocus/MarkerFrame/");

        File savePathWOMarker = new File(Environment
                .getExternalStorageDirectory().getPath()
                + "/HumanFocus/WithoutMarkerFrame/");

        if (savePathWMarker.isDirectory()) {
            String[] children = savePathWMarker.list();
            for (int i = 0; i < children.length; i++) {
                new File(savePathWMarker, children[i]).delete();
            }
        }

        if (savePathWOMarker.isDirectory()) {
            String[] children = savePathWOMarker.list();
            for (int i = 0; i < children.length; i++) {
                new File(savePathWOMarker, children[i]).delete();
            }
        }
        // change this if no Marker Video
        File src = new File("");
        File dst = new File("");
        if (mFilePathMarkers != null) {
            src = new File(mFilePathMarkers);
        }
        if (videoFileLocal != null) {
            dst = new File(videoFileLocal);
        }
        try {
            copyFile(src, dst);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        int maxNumber = 0;
        for (int i = 0; i < mCreateTraining.getAttachedFiles().size(); i++) {

            String fileName = mCreateTraining.getAttachedFiles().get(i)
                    .getDisplayName().substring(0, 2);

            if (isNumeric(fileName)) {
                if (Integer.parseInt(fileName) > maxNumber)
                    maxNumber = Integer.parseInt(fileName);
            }
        }

        mCreateTraining.attachFile(saveVideo(videoFileLocal,
                Constants.RT_CREATE_TRAINING, goodPointsLocal,
                badPointsLocal, maxNumber, videoFileLocal));
        updateReportItemsList();
        Toast.makeText(CreateTrainingActivity.this,
                "Video Processing is Successfully Completed",
                Toast.LENGTH_LONG).show();

        notGotoBack = true;
    }
}
在摄像机的活动结果上,创建异步任务并将其插入processList(AsyncTask的ArrayList)

这是我的日志

09-17 10:09:23.108: E/sizeee addxxxxxxxxxx(21007): 96
09-17 10:09:23.148: I/dalvikvm-heap(21007): Grow heap (frag case) to 144.206MB for 11059216-byte allocation
09-17 10:09:23.218: I/dalvikvm-heap(21007): Grow heap (frag case) to 151.585MB for 7738604-byte allocation
09-17 10:09:23.248: I/millisUntilFinished:(21007): 1794
09-17 10:09:23.248: E/sizeee addxxxxxxxxxx(21007): 99
09-17 10:09:23.278: I/dalvikvm-heap(21007): Grow heap (frag case) to 144.206MB for 11059216-byte allocation
09-17 10:09:23.368: E/sizeee addxxxxxxxxxx(21007): 102
09-17 10:09:23.418: I/dalvikvm-heap(21007): Grow heap (frag case) to 144.206MB for 11059216-byte allocation
09-17 10:09:23.478: I/dalvikvm-heap(21007): Grow heap (frag case) to 151.585MB for 7738604-byte allocation
09-17 10:09:23.508: E/sizeee addxxxxxxxxxx(21007): 105
09-17 10:09:23.538: I/dalvikvm-heap(21007): Grow heap (frag case) to 144.206MB for 11059216-byte allocation
09-17 10:09:23.608: E/sizeee addxxxxxxxxxx(21007): 108
09-17 10:09:23.668: I/dalvikvm-heap(21007): Grow heap (frag case) to 144.206MB for 11059216-byte allocation
09-17 10:09:23.728: I/dalvikvm-heap(21007): Grow heap (frag case) to 151.585MB for 7738604-byte allocation
09-17 10:09:23.758: E/sizeee addxxxxxxxxxx(21007): 111
09-17 10:09:23.788: I/dalvikvm-heap(21007): Grow heap (frag case) to 144.207MB for 11059216-byte allocation
09-17 10:09:23.838: E/sizeee addxxxxxxxxxx(21007): 114
09-17 10:09:23.868: I/dalvikvm-heap(21007): Grow heap (frag case) to 151.586MB for 11059216-byte allocation
09-17 10:09:23.908: I/dalvikvm-heap(21007): Grow heap (frag case) to 158.966MB for 7738604-byte allocation
09-17 10:09:25.478: D/MediaRecorder(21007): Current Package Name: uk.org.humanfocus.hfi
09-17 10:09:25.488: I/Choreographer(21007): Skipped 98 frames!  The application may be doing too much work on its main thread.
09-17 10:09:25.488: I/millisUntilFinished:(21007): 1791
09-17 10:09:26.498: I/millisUntilFinished:(21007): 1790
09-17 10:09:27.508: I/millisUntilFinished:(21007): 1789
09-17 10:09:28.508: I/millisUntilFinished:(21007): 1788
09-17 10:09:29.508: I/millisUntilFinished:(21007): 1787
09-17 10:09:30.508: I/millisUntilFinished:(21007): 1786
09-17 10:09:30.678: I/user interaction(21007): called
09-17 10:09:30.678: I/millisUntilFinished:(21007): 1799
09-17 10:09:31.698: I/millisUntilFinished:(21007): 1798
09-17 10:09:31.698: I/On Pause :(21007): called
09-17 10:09:32.318: I/Choreographer(21007): Skipped 30 frames!  The application may be doing too much work on its main thread.

我认为在您的情况下,您应该使用Android服务或Intent服务。 链接:

对于长时间的繁重操作,不应使用异步。 在我的例子中,我使用了带有新Runnables的Intent服务,它工作了。
如果您还有更多问题,请提问。

增加线程睡眠时间,现在看是1秒,改为5秒或10秒

 try {
                    Thread.sleep(10000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

看看你的日志,最后一行很有趣:

09-17 10:09:32.318: I/Choreographer(21007): Skipped 30 frames!  The application may be doing too much work on its main thread.
这对我来说很重要,因为它在调试过程中工作——断点给了它足够的时间来追赶

一般来说,@dadecki可能是正确的:对于android上的这么多处理,您可能应该使用后台服务。然而,如果你不想走这条路,那么问这样一个问题似乎是明智的:为什么应用程序在主线程上做了太多的工作。有几点建议:

  • 尽可能多地从
    onPostExecute
    移动到
    doInBackground
    -那里肯定有很多代码
  • 同时看看应用程序在主线程中还做了些什么:代码中是否有其他东西真的应该在异步任务(或服务)中

一旦你解决了这个问题,你将在一个更好的地方来确定什么仍然是错误的(如果有的话)

对于您的情况,建议使用。因为在同一时间,你可以有有限数量的AsynTask。请在调试时注意,它可能工作正常,因为在断点处,系统有时间完成挂起的异步任务&这就是为什么调试时池的最大大小永远不会达到


感谢

使用侦听器了解异步任务的执行状态检查此链接很抱歉,但此日志未提及任何崩溃,您可以使用崩溃日志获取新的logact转储并将其放在此处。
 try {
                    Thread.sleep(10000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
09-17 10:09:32.318: I/Choreographer(21007): Skipped 30 frames!  The application may be doing too much work on its main thread.