[英]how to pass BitmapShader class object using parcelable?
here is the exception 这是例外
java.lang.RuntimeException: Parcel: unable to marshal value android.graphics.BitmapShader@419d81a0
at android.os.Parcel.writeValue(Parcel.java:1235)
at com.imagepatterns.ShaderParcelalable.writeToParcel(ShaderParcelalable.java:47)
at android.os.Parcel.writeParcelable(Parcel.java:1254)
at android.os.Parcel.writeValue(Parcel.java:1173)
at android.os.Parcel.writeMapInternal(Parcel.java:591)
at android.os.Bundle.writeToParcel(Bundle.java:1619)
at android.os.Parcel.writeBundle(Parcel.java:605)
at android.content.Intent.writeToParcel(Intent.java:6470)
at android.app.ActivityManagerProxy.finishActivity(ActivityManagerNative.java:1921)
at android.app.Activity.finish(Activity.java:4135)
at com.imagepatterns.ImagePatternActivity.sendResultBack(ImagePatternActivity.java:111)
at com.imagepatterns.ImagePatternActivity.access$100(ImagePatternActivity.java:31)
at com.imagepatterns.ImagePatternActivity$1.onClick(ImagePatternActivity.java:52)
at android.view.View.performClick(View.java:4106)
at android.view.View$PerformClick.run(View.java:17052)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5059)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:792)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555)
at dalvik.system.NativeStart.main(Native Method)
And my code is 我的代码是
public class ShaderParcelalable implements Parcelable {
public BitmapShader getShader() {
return shader;
}
private BitmapShader shader;
protected ShaderParcelalable(Parcel in) {
this.shader = (BitmapShader) in.readValue(BitmapShader.class.getClassLoader());
}
public ShaderParcelalable(BitmapShader shader) {
this.shader = shader;
}
public static final Creator<ShaderParcelalable> CREATOR = new Creator<ShaderParcelalable>() {
@Override
public ShaderParcelalable createFromParcel(Parcel in) {
return new ShaderParcelalable(in);
}
@Override
public ShaderParcelalable[] newArray(int size) {
return new ShaderParcelalable[size];
}
};
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeValue(shader);
}
}
The BitmapShader class does not implement Parcelable, so you can't use this way. BitmapShader类未实现Parcelable,因此您不能使用这种方式。 Depending on your use case you could eg save the parameters you need to (re-)create the BitmapShader. 根据您的用例,您可以例如保存(重新)创建BitmapShader所需的参数。 In the case of the BitmapShader-class, you could try to save the 对于BitmapShader类,您可以尝试保存
in the Parcel. 在包裹中。 Then you could recreate your BitmapShader with this data. 然后,您可以使用此数据重新创建BitmapShader。 Not the best option, but on the other hand you might want to rethink your architecture. 这不是最佳选择,但另一方面,您可能需要重新考虑您的体系结构。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.