Android:无法添加窗口-令牌android.os.BinderProxy无效;您的活动正在进行吗?

时间:2018-11-26 11:17:08

标签: android multithreading image memory imageview

因此,当我单击“添加检查点”按钮时,我有一个可在自定义图像视图上绘制点的应用程序。每次添加新点时,都会发生两件事-

1)创建一条将刚添加的点和之前添加的点连接起来的线。 2)将线划分为点数为“ x”的点,并将点画在线上。 (请看所附的屏幕截图)

我基本上将List传递给自定义imageview类,从中我得到'x'的值。

As you can see the points are divided equally on the line based on the value of 'x'

现在,每当x的值超过70或80(任何高数字)时,应用程序就会崩溃,并且出现以下错误-

无法添加窗口-令牌android.os.BinderProxy无效;您的活动正在进行吗?

由于繁琐的UI操作,我的活动即将结束。有什么建议吗?

这是我自定义imageview中的函数,该函数将点添加到要显示的点列表中。

public void addMarker(float a, float b, Context ctx, List<SampleModel> mainList) {
    DBHelperCSV helperCSV = new DBHelperCSV(ctx);
    if (!mainList.isEmpty()) {
        for (SampleModel m : mainList) {
            System.out.println("Rushi : SSTList : " + m.sst);
        }
    }
    int partsCount = mainList.size();
    pointNumber = pointNumber + 1;
    matrix.invert(inverse);
    float[] pts = {
            a + 45, b + 45
    };
    inverse.mapPoints(pts);
    System.out.println("Rushi : Passed points :" + a + " " + b);
    PointF mainPoint = new PointF(pts[0], pts[1]);
    float mainSST = -999;
    if (!mainList.isEmpty()) {
        mainSST = Float.parseFloat(mainList.get(0).getSst());
    }
    PointModel mainPointModel = new PointModel(mainPoint, mainSST);
    markers.add(mainPointModel);
    PointF mainConvertedPoint = getConvertedPoint(mainPoint.x, mainPoint.y);


    //
    //pts[0] and pts[1] is the actual image point which is in markers list
    System.out.println("Rushi : Mapped points :" + pts[0] + " " + pts[1]);
    PointF convertedPoint = getConvertedPoint(pts[0], pts[1]);
    System.out.println("Rushi : Converted points :" + convertedPoint.x + " " + convertedPoint.y);
    convertedPoints.add(new PointModel(convertedPoint, mainSST));
    invalidate();
    Toast.makeText(ctx, "(" + convertedPoint.x + "," + convertedPoint.y + ")", Toast.LENGTH_SHORT).show();
    if (markers.size() > 1) {
        //Add partsCount-1 points between the markers.size() - 1 and markers.size() - 2
        PointF justAddedPoint = markers.get(markers.size() - 1).point;
        PointF previousPoint = markers.get(markers.size() - 2).point;
        System.out.println("Divide : Previous point - " + "(" + previousPoint.x + "," + previousPoint.y + ")");
        System.out.println("Divide : Just added point - " + "(" + justAddedPoint.x + "," + justAddedPoint.y + ")");
        //Find d and d/n

        if (partsCount > 2 && !((Activity)ctx).isFinishing()) {
            double dist = Math.sqrt(((justAddedPoint.x - previousPoint.x) * (justAddedPoint.x - previousPoint.x)) + ((justAddedPoint.y - previousPoint.y) * (justAddedPoint.y - previousPoint.y)));
            double tParts = partsCount - 1;
            double dN = dist / tParts;

            // new BackgroundWorker(ctx, dist, tParts - 1, dN, previousPoint, justAddedPoint, mainList).execute();
            for (int i = 0; i < tParts - 1; i++) {
                double m = (i + 1) * dN;
                double n = dist - ((i + 1) * dN);
                PointF point = new PointF();
                double x = ((m * justAddedPoint.x + n * previousPoint.x) / dist);
                double y = ((m * justAddedPoint.y + n * previousPoint.y) / dist);
                point.set((float) x, (float) y);
                //Map and add
                float[] pts2 = {(float) x, (float) y};
                inverse.mapPoints(pts2);
                //Point and value
                PointModel pointModel = new PointModel();
                float sst = -999;
                if (!mainList.isEmpty()) {
                    sst = Float.parseFloat(mainList.get(i + 1).getSst());
                }
                pointModel.setPoint(point);
                pointModel.setSst(sst);
                semiMarkers.add(pointModel);
                convertedPoints.add(new PointModel(getConvertedPoint(point.x, point.y), sst));

                System.out.println("Divide : Point " + (i + 1) + " - (" + point.x + "," + point.y + ")");
                try {
                    Thread.sleep(4);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }

    }

}

这是我的onDraw()函数-

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    origWidth = this.getDrawable().getIntrinsicWidth();
    origLength = this.getDrawable().getIntrinsicHeight();
    if (markers.size() > 1) {
        for (int i = 0; i < markers.size() - 1; i++) {
            paintLine.setColor(Color.WHITE);
            float[] pts = {markers.get(i).point.x, markers.get(i).point.y, markers.get(i + 1).point.x, markers.get(i + 1).point.y};
            matrix.mapPoints(pts);
            canvas.drawLine(pts[0], pts[1], pts[2], pts[3], paintLine);
        }
    }

    for (int i = 0; i < markers.size(); i++) {
        float[] pts = {markers.get(i).point.x, markers.get(i).point.y};
        float sst = markers.get(i).sst;
        matrix.mapPoints(pts);

        if (sst <= 0 && sst >= -80) {
            paintMain.setColor(Color.RED);
        } else if (sst <= -80 && sst >= -90) {
            paintMain.setColor(Color.BLUE);
        } else if (sst <= -90 && sst >= -100) {
            paintMain.setColor(Color.YELLOW);
        } else if (sst <= -100 && sst >= -110) {
            paintMain.setColor(getResources().getColor(R.color.lightgreen));
        } else if (sst <= -110 && sst >= -140) {
            paintMain.setColor(Color.GREEN);
        } else if (sst == -999) {
            paintMain.setColor(Color.BLACK);
        }
        canvas.drawCircle(pts[0], pts[1], 22, paintMain);
    }

    for (int i = 0; i < semiMarkers.size(); i++) {
        float[] pts = {semiMarkers.get(i).point.x, semiMarkers.get(i).point.y};
        float sst = semiMarkers.get(i).sst;
        matrix.mapPoints(pts);
        if (sst <= 0 && sst >= -80) {
            paintForSemi.setColor(Color.RED);
        } else if (sst <= -80 && sst >= -90) {
            paintForSemi.setColor(Color.BLUE);
        } else if (sst <= -90 && sst >= -100) {
            paintForSemi.setColor(Color.YELLOW);
        } else if (sst <= -100 && sst >= -110) {
            paintForSemi.setColor(getResources().getColor(R.color.lightgreen));
        } else if (sst <= -110 && sst >= -140) {
            paintForSemi.setColor(Color.GREEN);
        } else if (sst == -999) {
            paintForSemi.setColor(Color.BLACK);
        }
        canvas.drawCircle(pts[0], pts[1], 11, paintForSemi);
    }
}

0 个答案:

没有答案