Skip to content

Commit

Permalink
Fix demo app crash
Browse files Browse the repository at this point in the history
The customer id was not persisted through configuration changes causing
the BraintreeFragment to get reset and cause a NPE.
  • Loading branch information
lkorth committed Apr 11, 2017
1 parent d1f24ca commit 3039c03
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions Demo/src/main/java/com/braintreepayments/demo/BaseActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ public abstract class BaseActivity extends AppCompatActivity implements OnReques
PaymentMethodNonceCreatedListener, BraintreeCancelListener, BraintreeErrorListener,
ActionBar.OnNavigationListener {

private static final String KEY_AUTHORIZATION = "com.braintreepayments.demo.KEY_AUTHORIZATION";
private static final String EXTRA_AUTHORIZATION = "com.braintreepayments.demo.EXTRA_AUTHORIZATION";
private static final String EXTRA_CUSTOMER_ID = "com.braintreepayments.demo.EXTRA_CUSTOMER_ID";

protected String mAuthorization;
protected String mCustomerId;
Expand All @@ -55,8 +56,9 @@ protected void onCreate(Bundle savedInstanceState) {

mLogger = LoggerFactory.getLogger(getClass().getSimpleName());

if (savedInstanceState != null && savedInstanceState.containsKey(KEY_AUTHORIZATION)) {
mAuthorization = savedInstanceState.getString(KEY_AUTHORIZATION);
if (savedInstanceState != null) {
mAuthorization = savedInstanceState.getString(EXTRA_AUTHORIZATION);
mCustomerId = savedInstanceState.getString(EXTRA_CUSTOMER_ID);
}
}

Expand Down Expand Up @@ -101,7 +103,8 @@ private void handleAuthorizationState() {
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
if (mAuthorization != null) {
outState.putString(KEY_AUTHORIZATION, mAuthorization);
outState.putString(EXTRA_AUTHORIZATION, mAuthorization);
outState.putString(EXTRA_CUSTOMER_ID, mCustomerId);
}
}

Expand Down

0 comments on commit 3039c03

Please sign in to comment.