主线程中的工作过多问题 warning.How 添加 AsyncTask?

Too much work in main thread issue warning.How add AsyncTask?

伙计们帮我添加异步任务 app.I 有问题添加 this.Maybe 任何提示如何实现 this.Its rtsp 视频 player.App 与网络服务器通信并使用 canvas.Async 任务绘制视频有助于解决主线程和跳过帧的问题?

if (frameNum >= skipNum) {
  //Log.d(TAG, String.format("onFrame: nChannel = %d, width = %d, height = %d", nChannel, width, height));
  try {
    Canvas canvas = surface.lockCanvas(null);

      try {

        int area = width * height;
        int pixels[] = new int[area];

        for (int i = 0; i < area; i++) {
          int r = frame[3 * i];
          int g = frame[3 * i + 1];
          int b = frame[3 * i + 2];
          if (r < 0) r += 255;
          if (g < 0) g += 255;
          if (b < 0) b += 255;
          pixels[i] = Color.rgb(r, g, b);
        }

        Bitmap bmp = Bitmap.createBitmap(pixels, width, height, Bitmap.Config.ARGB_8888);
        canvas.drawBitmap(bmp, null, videoRect, null);

      } finally {
        surface.unlockCanvasAndPost(canvas);
      }
    } catch (Exception e) {
      e.printStackTrace();
    }

    frameNum = 0;
  }
}

不确定你 Android API 级别,但是 Async Task 现已弃用。

此 class 已在 API 级别 30 中弃用。 请改用标准 java.util.concurrent 或 Kotlin 并发实用程序。

由于您的代码是 Java,这里是并发的 link:https://developer.android.com/reference/java/util/concurrent/package-summary