Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/201.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
如何将Path对象传递给新活动(Android)_Android - Fatal编程技术网

如何将Path对象传递给新活动(Android)

如何将Path对象传递给新活动(Android),android,Android,在我当前的活动中,我有一个用户用手指在屏幕上绘制的路径对象。我想将这个Path对象传递到下一个活动,大概是通过一个Intent Intent myIntent = new Intent(activity, TrainingActivity.class); myIntent.putExtra("image",byteArray); /* Pass the Path to the Intent here*/ // Start new activity with this new intent a

在我当前的活动中,我有一个用户用手指在屏幕上绘制的路径对象。我想将这个Path对象传递到下一个活动,大概是通过一个Intent

Intent myIntent = new Intent(activity, TrainingActivity.class);
myIntent.putExtra("image",byteArray);

/* Pass the Path to the Intent here*/

// Start new activity with this new intent
activity.startActivity(myIntent);
我尝试过使用approxite()方法将路径近似为点数组,如下所示

float[] pArray = path.approximate(0.5);
myIntent.putExtra("arr",pArray);

但是android给了我一个错误:“无法解析‘近似(双)’方法”,由于某种原因,我无法让它工作,所以这个方法似乎是不可行的。

为了防止将来有人会遇到同样的问题,我想出的解决方案是每当有人触摸屏幕时记录x和y坐标,当我在修路的时候。我将这些坐标放置到ArrayList中,如下所示:

ArrayList<Float> xCoords = new ArrayList<Float>();
ArrayList<Float> yCoords = new ArrayList<Float>();

 @Override
    public boolean onTouchEvent(MotionEvent event) {
        // Get the coordinates of the touch event
        float eventX = event.getX();
        float eventY = event.getY();

        switch (event.getAction()) {
            // When a finger touches down on the screen
            case MotionEvent.ACTION_DOWN:
                // Add the coordinates to array lists
                xCoords.add(eventX);
                yCoords.add(eventY);
                // Set a new starting point
                path.moveTo(eventX, eventY);
                return true;
            // When a finger moves around on the screen
            case MotionEvent.ACTION_MOVE:
                xCoords.add(eventX);
                yCoords.add(eventY);
                // Connect the points
                path.lineTo(eventX, eventY);
                break;
           ...
           ...
           ...

然后,如果您真的需要一个路径对象,只需使用这些点创建一个新路径。

是的,
android.graphics.Path
没有这样的公共/可见方法-它被
@hide
注释根据文档()隐藏,此方法仅在android O预览中可用。
Intent myIntent = new Intent(activity, TrainingActivity.class);
                                myIntent.putExtra("image",byteArray);

// Add the two arrays with points
myIntent.putExtra("Xpoints",xCoords);
myIntent.putExtra("Ypoints",yCoords);

// Start new activity with this new intent
activity.startActivity(myIntent);