Android 应用程序自动退出,无任何警告或错误

Android 应用程序自动退出,无任何警告或错误,android,android-ndk,crash-reports,android-logcat,remoteexception,Android,Android Ndk,Crash Reports,Android Logcat,Remoteexception,我使用tesseract库开发了OCR应用程序 在执行以下代码期间,应用程序已退出: /*... ... Other Code stuff ...*/ protected Boolean doInBackground(String... arg0) { /*... ... Other Code stuff ...*/ Pix pix = getPixFromBitmap(bitmap); pix = preprocess(pix); Pi

我使用tesseract库开发了OCR应用程序

在执行以下代码期间,应用程序已退出:

/*...
... Other Code stuff
...*/
    protected Boolean doInBackground(String... arg0) {

    /*...
    ... Other Code stuff
    ...*/
    Pix pix = getPixFromBitmap(bitmap);
    pix = preprocess(pix);
    Pixa pixa = slice(pix); // Code Updated

    try {
        baseApi.setPageSegMode(TessBaseAPI.PSM_SINGLE_LINE);

        int num = pixa.size();

        for (int i = 0; i < num; i++) {
            Pix pixi = pixa.getPix(i);

            /*...
            ... Other Code stuff
            ...*/
        }
        pixa.recycle();
        baseApi.end();

    } catch (RuntimeException e) {
Log.e("OcrRecognizeAsyncTask","Caught RuntimeException in request to Tesseract. Setting state to CONTINUOUS_STOPPED.");
        e.printStackTrace();
        try {
            // baseApi.clear();
            activity.stopHandler();
        } catch (NullPointerException e1) {
            // Continue
        }
        return false;
    }

    private Pixa slice(Pix pix) {
    HydrogenTextDetector htd = new HydrogenTextDetector();
    HydrogenTextDetector.Parameters hydrogenParams = htd.getParameters();
    hydrogenParams.debug = false;
    hydrogenParams.skew_enabled = true;
    htd.setParameters(hydrogenParams);

    htd.setSourceImage(pix);
    pix.recycle();
    htd.detectText();
    Pixa unsorted = htd.getTextAreas();
    Pixa pixa = unsorted.sort(Constants.L_SORT_BY_X, Constants.L_SORT_DECREASING);
    unsorted.recycle();
    htd.clear();
    return pixa;
}
我正在将位图转换为Leptonica Pix对象,而不是将Pix转换为Leptonica Pixa对象,并进行OCR重组

在处理过程中,有时OCR重组成功,有时android主屏幕自动出现

我不知道这背后的问题是什么,为什么会出现RemoteException警告

请帮我解决这个问题


谢谢,

您不能在异步任务之间结束baseApi。这就是您遇到的崩溃问题

您使用了以下代码

pixa.recycle();
baseApi.end();
注释下面的行,然后尝试运行应用程序,它可能会解决您的问题

pixa.recycle();
// baseApi.end();
==================================================================================

自动清除堆内存您可以实现以下代码:

public void onCreate(Bundle savedInstanceState) {
{
    clearMemoryCountDownTimer mClearMemoryCountDownTimer = new clearMemoryCountDownTimer(5000, 5000).start();
}
private class clearMemoryCountDownTimer extends CountDownTimer {

    public clearMemoryCountDownTimer(long millisInFuture,
            long countDownInterval) {
        super(millisInFuture, countDownInterval);
    }

    @Override
    public void onFinish() {
        start();
        Log.i(TAG, "Timer Finished");
    }

    @Override
    public void onTick(long millisUntilFinished) {
        if (Debug.getNativeHeapFreeSize() < 100000) {
            clearMemory();
            Log.i(TAG, "requiredClearMemory");
        }
        Log.i(TAG, "getNativeHeapSize : " + Debug.getNativeHeapSize());
        Log.i(TAG,
                "getNativeHeapFreeSize : " + Debug.getNativeHeapFreeSize());
        Log.i(TAG,
                "getNativeHeapAllocatedSize : "
                        + Debug.getNativeHeapAllocatedSize());

    }

    void clearMemory() {
        Log.i(TAG, "System.gc()-Start");
        System.gc();
        Log.i(TAG, "System.gc()-End");
    }
}
public void onCreate(Bundle savedInstanceState){
{
clearMemoryCountDownTimer mClearMemoryCountDownTimer=新的clearMemoryCountDownTimer(50005000).start();
}
私有类clearMemoryCountDownTimer扩展了CountDownTimer{
公共clearMemoryCountDownTimer(长毫秒),
长倒计时间隔){
超级(毫秒未来,倒计时间隔);
}
@凌驾
公共无效onFinish(){
start();
Log.i(标记“计时器完成”);
}
@凌驾
公共void onTick(长毫秒未完成){
if(Debug.getNativeHeapFreeSize()<100000){
clearMemory();
Log.i(标签“requiredClearMemory”);
}
i(标记“getNativeHeapSize:+Debug.getNativeHeapSize());
Log.i(标签,
getNativeHeapFreeSize:+Debug.getNativeHeapFreeSize());
Log.i(标签,
“GetNativeHeapLocatedSize:”
+getNativeHeapLocatedSize());
}
void clearMemory(){
Log.i(标记“System.gc()-Start”);
gc();
Log.i(标记“System.gc()-End”);
}
}

您在哪一行看到异常?这就是问题所在,在应用程序执行期间没有引发错误,但它会自动显示主屏幕,并且LogCat仅显示一条警告W/InputManagerService(102):Get RemoteException向pid 4880 uid 10062发送setActive(false)通知此警告(W/InputManagerService可能没有任何意义,因为我经常在一个运行良好的opengl应用程序中使用它。但是上面提到的另一个例外更有趣。
public void onCreate(Bundle savedInstanceState) {
{
    clearMemoryCountDownTimer mClearMemoryCountDownTimer = new clearMemoryCountDownTimer(5000, 5000).start();
}
private class clearMemoryCountDownTimer extends CountDownTimer {

    public clearMemoryCountDownTimer(long millisInFuture,
            long countDownInterval) {
        super(millisInFuture, countDownInterval);
    }

    @Override
    public void onFinish() {
        start();
        Log.i(TAG, "Timer Finished");
    }

    @Override
    public void onTick(long millisUntilFinished) {
        if (Debug.getNativeHeapFreeSize() < 100000) {
            clearMemory();
            Log.i(TAG, "requiredClearMemory");
        }
        Log.i(TAG, "getNativeHeapSize : " + Debug.getNativeHeapSize());
        Log.i(TAG,
                "getNativeHeapFreeSize : " + Debug.getNativeHeapFreeSize());
        Log.i(TAG,
                "getNativeHeapAllocatedSize : "
                        + Debug.getNativeHeapAllocatedSize());

    }

    void clearMemory() {
        Log.i(TAG, "System.gc()-Start");
        System.gc();
        Log.i(TAG, "System.gc()-End");
    }
}