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

java.lang.IllegalStateException: Activity has been destroyed when trying to create BraintreeFragment #104

Closed
MiralDesai opened this issue Jun 6, 2016 · 6 comments

Comments

@MiralDesai
Copy link

MiralDesai commented Jun 6, 2016

I seem to be getting this crash a fair bit when trying to create a new instance of BraintreeFragment with v2 of the SDK. This is because I can initialise a new BraintreeFragment like this:

try {
    braintreeFragment = BraintreeFragment.newInstance(context, clientToken);
} catch (InvalidArgumentException e) {
    e.printStackTrace();
}

but the user may have already left the activity, so when the FragmentManager returns and tries to attach the BraintreeFragment to the activity an exception is thrown, because the activity has already been destroyed. Of course this is causing my app to crash.

I assume you guys handle everything to do with the Fragment and it's transactions, so I feel like this is a bug with the SDK in that it's not properly handled. The Fragment should not be attached if the activity has been destroyed.

Let me know what you think.

@lkorth
Copy link
Member

lkorth commented Jun 6, 2016

@MiralDesai: yes, this is something the SDK should check and handle. Do you have a stacktrace you can share?

@MiralDesai
Copy link
Author

MiralDesai commented Jun 7, 2016

Yup sure can.

Here you go:

Fatal Exception: java.lang.IllegalStateException: Activity has been destroyed at android.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1350) at android.app.BackStackRecord.commitInternal(BackStackRecord.java:729) at android.app.BackStackRecord.commit(BackStackRecord.java:705) at com.braintreepayments.api.BraintreeFragment.newInstance(SourceFile:128) at com.app.AddPaymentMethod.initialiseBraintreeFragment(SourceFile:182) at com.app.AddPaymentMethod.access$1200(SourceFile:66) at com.app.AddPaymentMethod$GetClientToken.onPostExecute(SourceFile:652) at com.app.AddPaymentMethod$GetClientToken.onPostExecute(SourceFile:633) at android.os.AsyncTask.finish(AsyncTask.java:636) at android.os.AsyncTask.access$500(AsyncTask.java:177) at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:653) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5254) at java.lang.reflect.Method.invoke(Method.java) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

The line is points too is the line I posted in my opening post.

braintreeFragment = BraintreeFragment.newInstance(context, clientToken);

Not sure what version of the SDK I'm using, the latest because I'm following Braintree's guide

'com.braintreepayments.api:braintree:2.+'

@lkorth lkorth closed this as completed in 1f954c6 Jun 7, 2016
@lkorth
Copy link
Member

lkorth commented Jun 7, 2016

@MiralDesai thanks for the report. I've added and fix, it will go out in the next release.

@MiralDesai
Copy link
Author

Thanks, do you have a timeline for the next release? Would be handy to know so I can track it. Since I'm using 2.+ I won't know.

@lkorth
Copy link
Member

lkorth commented Jun 7, 2016

I don't have a timeline, but it should be some time this week. We have a Google Group that announces releases that you can subscribe to find out when the new version comes out.

@MiralDesai
Copy link
Author

Fantastic thanks.

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

2 participants