简体   繁体   English

如果已成功使用Parcelised数据,即使我已退出Parcelised数据,我退出应用程序时Android应用程序也会崩溃

[英]Android app crashes when I quit the app if Parcelised data has been used at some point, even though that data was successfully Parcelized

I have a strange crash on both the Genymotion Android simulator and my Huawei Nexus 6P . 我在Genymotion Android模拟器和我的Huawei Nexus 6P上都Genymotion了奇怪的崩溃。 I have a screenshot that I am sending to another Anko Component successfully - obviously it is Parcelable: 我有一个截图,可以成功发送到另一个Anko Component -显然是可打包的:

@Parcelize
data class ColourBoardScreenShot(var screenshot: @RawValue BitmapDrawable) : Parcelable

However, if I take the screenshot and anytime later quit the app by pressing the circle button at the bottom of the screen the app crashes with the following stack trace: 但是,如果我截取屏幕截图,然后以后再按屏幕底部的圆圈按钮退出应用程序,则应用程序将崩溃并显示以下堆栈跟踪:

FATAL EXCEPTION: main
Process: uk.co.davechambers.pegboard, PID: 2292
java.lang.RuntimeException: Parcel: unable to marshal value
android.graphics.drawable.BitmapDrawable@4cdb04c
at android.os.Parcel.writeValue(Parcel.java:1477)
at uk.co.davechambers.pegboard.models.ColourBoardScreenShot.writeToParcel(ColourBoardScreenShot.kt:0)
at android.os.Parcel.writeParcelable(Parcel.java:1496)
at android.os.Parcel.writeValue(Parcel.java:1402)
at android.os.Parcel.writeArrayMapInternal(Parcel.java:724)
at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1408)
at android.os.Bundle.writeToParcel(Bundle.java:1157)
at android.os.Parcel.writeBundle(Parcel.java:764)
at android.support.v4.app.FragmentState.writeToParcel(Fragment.java:154)
at android.os.Parcel.writeTypedArray(Parcel.java:1307)
at android.support.v4.app.FragmentManagerState.writeToParcel(FragmentManager.java:617)
at android.os.Parcel.writeParcelable(Parcel.java:1496)
at android.os.Parcel.writeValue(Parcel.java:1402)
at android.os.Parcel.writeArrayMapInternal(Parcel.java:724)
at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1408)
at android.os.Bundle.writeToParcel(Bundle.java:1157)
at android.os.Parcel.writeBundle(Parcel.java:764)
at android.app.ActivityManagerProxy.activityStopped(ActivityManagerNative.java:3633)
at android.app.ActivityThread$StopInfo.run(ActivityThread.java:3773)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)

Can anyone tell me where I'm going wrong? 谁能告诉我我要去哪里错了?

EDIT : 编辑

If I try and replace the ColourBoardScreenShot by using a plugin to generate the Parcelize code I get Unresolved reference on read and write : 如果我尝试通过使用插件来生成Colcelize代码来替换ColourBoardScreenShot ,则在readwrite会出现Unresolved reference

data class ColourBoardScreenShot(var screenshot: @RawValue BitmapDrawable) : Parcelable {
constructor(source: Parcel) : this(
        source.read[@kotlinx.android.parcel.RawValue] BitmapDrawable ()
)

override fun describeContents() = 0

override fun writeToParcel(dest: Parcel, flags: Int) = with(dest) {
    write[@kotlinx.android.parcel.RawValue] BitmapDrawable (screenshot)
}

companion object {
    @JvmField
    val CREATOR: Parcelable.Creator<ColourBoardScreenShot> = object : Parcelable.Creator<ColourBoardScreenShot> {
        override fun createFromParcel(source: Parcel): ColourBoardScreenShot = ColourBoardScreenShot(source)
        override fun newArray(size: Int): Array<ColourBoardScreenShot?> = arrayOfNulls(size)
    }
}
}

I changed my ColourBoardScreenShot to the following: 我将ColourBoardScreenShot更改为以下内容:

@Parcelize
data class ColourBoardScreenShot(var screenshot: ByteArray) : Parcelable

So instead of @RawValue BitmapDrawable I use ByteArray and the crash stopped. 因此,我使用ByteArray而不是@RawValue BitmapDrawable ,崩溃停止了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我的应用已经成功安装在Android上,但一旦加载就会崩溃 - My app has successfully been installed on Android, but crashes as soon as it loads 即使我添加了条件,应用程序在没有互联网时也会崩溃 - App crashes when there is no internet even though I have added conditions to it Android:当我尝试从意图中检索数据时应用程序崩溃 - Android:App crashes when i try to retrieve data from intent 将数据发送到服务器时,Android应用程序崩溃 - Android App Crashes When Sending Data To Server 将数据保存到数据库时,Android应用程序崩溃 - Android app crashes when saving data to database Firebase 要求初始化应用程序,即使它已经被初始化 - Firebase Asking to initialize app even though it has already been initialized 我的Android应用程序崩溃,即使我正在捕捉它导致崩溃的异常 - My Android app crashes even though I am catching the exception it says is causing the crash 如何知道应用是否已在android中成功安装 - How to know if an app has been installed successfully in android 即使hasVibrator()返回true,应用程序在使用Vibrator时也会崩溃 - App crashes when using Vibrator, even though hasVibrator() returns true Application.Quit()导致游戏应用崩溃 - Game App Crashes when Application.Quit()
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM