Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crashes when trying to launch activity in ConfirmButtonClickListener #48

Closed
rosenpin opened this issue Feb 14, 2021 · 5 comments
Closed

Comments

@rosenpin
Copy link

rosenpin commented Feb 14, 2021

Hi again

I'm trying to launch the play store activity if the user rated 4+ (skipping the second dialog, I don't think it's necessary)
Here is my code:

    fun rate() : Boolean {
        return AppRating.Builder(activity)
            ...  
            .setConfirmButtonClickListener { userRating ->
                if (userRating >= 4)
                    OpenLinksUtils.openPlayStoreURL(activity)
            }
            ...
            .showIfMeetsConditions()
    }
            ...
    fun openWebAddress(context: Context, address: String) {
            val browserIntent = Intent(Intent.ACTION_VIEW, Uri.parse(address))
            browserIntent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
            context.startActivity(browserIntent)
     }

   fun openPlayStoreURL(context: Context) {
            openWebAddress(context, Consts.APP_PAGE)
      }

When I tap the confirm button, my app crashes with the dialog, this is the error

    java.lang.RuntimeException: Parcelable encountered IOException writing serializable object (name = com.suddenh4x.ratingdialog.dialog.DialogOptions)

This is the full stack trace

    java.lang.RuntimeException: Parcelable encountered IOException writing serializable object (name = com.suddenh4x.ratingdialog.dialog.DialogOptions)
        at android.os.Parcel.writeSerializable(Parcel.java:2125)
        at android.os.Parcel.writeValue(Parcel.java:1895)
        at android.os.Parcel.writeArrayMapInternal(Parcel.java:987)
        at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1620)
        at android.os.Bundle.writeToParcel(Bundle.java:1303)
        at android.os.Parcel.writeBundle(Parcel.java:1056)
        at androidx.fragment.app.FragmentState.writeToParcel(FragmentState.java:125)
        at android.os.Parcel.writeTypedObject(Parcel.java:1749)
        at android.os.Parcel.writeTypedList(Parcel.java:1628)
        at android.os.Parcel.writeTypedList(Parcel.java:1585)
        at androidx.fragment.app.FragmentManagerState.writeToParcel(FragmentManagerState.java:51)
        at android.os.Parcel.writeParcelable(Parcel.java:1916)
        at android.os.Parcel.writeValue(Parcel.java:1822)
        at android.os.Parcel.writeArrayMapInternal(Parcel.java:987)
        at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1620)
        at android.os.Bundle.writeToParcel(Bundle.java:1303)
        at android.app.IActivityTaskManager$Stub$Proxy.activityStopped(IActivityTaskManager.java:4918)
        at android.app.servertransaction.PendingTransactionActions$StopInfo.run(PendingTransactionActions.java:145)
        at android.os.Handler.handleCallback(Handler.java:938)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:246)
        at android.app.ActivityThread.main(ActivityThread.java:8425)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:596)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)
     Caused by: java.io.NotSerializableException: io.rosenpin.dmme.activities.root.Rate
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1240)
        at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1604)
        at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1565)
        at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1488)
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1234)
        at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1604)
        at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1565)
        at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1488)
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1234)
        at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1604)
        at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1565)
        at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1488)
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1234)
        at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:354)
        at android.os.Parcel.writeSerializable(Parcel.java:2120)
        at android.os.Parcel.writeValue(Parcel.java:1895) 
        at android.os.Parcel.writeArrayMapInternal(Parcel.java:987) 
        at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1620) 
        at android.os.Bundle.writeToParcel(Bundle.java:1303) 
        at android.os.Parcel.writeBundle(Parcel.java:1056) 
        at androidx.fragment.app.FragmentState.writeToParcel(FragmentState.java:125) 
        at android.os.Parcel.writeTypedObject(Parcel.java:1749) 
        at android.os.Parcel.writeTypedList(Parcel.java:1628) 
        at android.os.Parcel.writeTypedList(Parcel.java:1585) 
        at androidx.fragment.app.FragmentManagerState.writeToParcel(FragmentManagerState.java:51) 
        at android.os.Parcel.writeParcelable(Parcel.java:1916) 
        at android.os.Parcel.writeValue(Parcel.java:1822) 
        at android.os.Parcel.writeArrayMapInternal(Parcel.java:987) 
        at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1620) 
        at android.os.Bundle.writeToParcel(Bundle.java:1303) 
        at android.app.IActivityTaskManager$Stub$Proxy.activityStopped(IActivityTaskManager.java:4918) 
        at android.app.servertransaction.PendingTransactionActions$StopInfo.run(PendingTransactionActions.java:145) 
        at android.os.Handler.handleCallback(Handler.java:938) 
        at android.os.Handler.dispatchMessage(Handler.java:99) 
        at android.os.Looper.loop(Looper.java:246) 
        at android.app.ActivityThread.main(ActivityThread.java:8425) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:596) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)
@rosenpin rosenpin changed the title Crashes when trying to launch activity in confirmbuttonclicklistener Crashes when trying to launch activity in ConfirmButtonClickListener Feb 14, 2021
@SuddenH4X
Copy link
Owner

Hi @rosenpin,

the crash occurs because the app goes into background when your confirmButtonClickListener is called (userRating >= 4). And because of that the dialog gets serialized and so your confirmButtonClickListener which leads to a crash because of the reference to the activity. To fix it you can use a LiveData like I did in the example app.

Having said that your code won't work either way. Even if you open the Play Store listing yourself you'll not be able to prevent the library from showing the second dialog. Skipping it isn't possible at the moment.

PS: It doesn't help you with the issue but you could also use the method provided by the library to open the Play Store listing: AppRating.openPlayStoreListing(this)

@rosenpin
Copy link
Author

Thanks for the detailed response :)

It's just that it's a very weird behavior, I wouldn't expect my app to crash when trying to start an activity on a dialog close callback, I think this should defiantly be avoided by default (without the use of livesata) if possible

@SuddenH4X
Copy link
Owner

You're right. I'm aware of this issue and will probably fix it with the next release. In the meantime you can use LiveData/Flow/... to bypass the crash.

@Monabr
Copy link

Monabr commented Apr 30, 2021

@SuddenH4X can it be related to my issue #50 ?

@SuddenH4X
Copy link
Owner

Fixed with #59.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants