Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/358.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
Java 无法从捆绑包中检索Paint.Cap类型的数据_Java_Android_Android Intent_Bundles - Fatal编程技术网

Java 无法从捆绑包中检索Paint.Cap类型的数据

Java 无法从捆绑包中检索Paint.Cap类型的数据,java,android,android-intent,bundles,Java,Android,Android Intent,Bundles,我到处寻找这个问题,但找不到任何答案 我正在通过这样的意图发送数据 MainActivity.java Intent intent = new Intent(MainActivity.this, SecondActivity.class); intent.putExtra("key",Paint.Cap.SQUARE); startActivity(intent); 我的问题是检索它,我不知道使用哪种get方法,我也找不到任何在线来源告诉我 S

我到处寻找这个问题,但找不到任何答案

我正在通过这样的意图发送数据

MainActivity.java

Intent intent = new Intent(MainActivity.this, SecondActivity.class);
            intent.putExtra("key",Paint.Cap.SQUARE);
            startActivity(intent);
我的问题是检索它,我不知道使用哪种get方法,我也找不到任何在线来源告诉我

SecondActivity.java

Bundle extras = getIntent().getExtras();

    if(extras !=null)
    {
        if(extras.containsKey("key"))
        {
            Paint.Cap shape = //which method to use here?

        }
    }
如果它是如此愚蠢,请告诉我,我仍然是一个初学者,并尽我最大的努力找到自己的东西

谢谢。

关键在于Paint.Cap是一个枚举,因此它实现了可序列化的接口

这意味着您调用了接受序列化的putExtra版本

要想再把它弄出来,你可以

Paint.Cap shape = (Paint.Cap) extras.getSerializable("key");
可能重复的