有没有其他方法可以在单声道/安卓应用程序中使用更多的 cpu 而不是线程?请给一些建议。
谢谢,
您可以像这样实现使每次都无效的 Canvas:
private class Painter extends View{
        ArrayList<Point> points;
    public Painter(Context context){
        super(context);
    }
    public void draw() {
    points = new ArrayList<Point();
            for (int i = 0; i < 10000; i++) {
                //assign Points to the array
                Point p = new Point();
                p.x = 10;
                p.y = 30;
                points.add(p);
            }
            nameOfTheInstancePainter.invalidate();
    }
    @Override 
    protected void onDraw(Canvas c) {
        for (int i = 0; i < 10000; i++) {
                //paint aaaall the points
            }
        nameOfTheInstancePainter.invalidate(); //that will cause the ReDraw of everything everytime
    }
}
哦,顺便说一句,绘制画布使用不同的线程,这就是我编写此代码的原因!
多么奇怪的问题。您可以在主线程中执行各种处理器密集型操作。读取和写入位图数据,执行各种计算等。为什么要这样做?您希望占用多少 CPU?
不知道它的用途是什么,但这不使用任何工作线程并且会很好地吸收 CPU:
[Activity(MainLauncher = true)]
public class PointlessActivity : Activity
{
    protected override void OnCreate(Bundle bundle)
    {
        while(true) { }
    }
}