Note that there are some explanatory texts on larger screens.

plurals
  1. POPayPal Integration with Android
    primarykey
    data
    text
    <p>I have seen some related questions but none focusing on the specific problem I have:</p> <p>I'm using the PayPal MPL Library.</p> <p>I build my PayPalPayment object, then create the activity for the checkout to occur. That runs fine. My problem is, on the ResultDelegate I need to call a function from my activity, that occurs after the payment and makes some changes (such as storing SharedPreferences, etc.).</p> <p>So something like this:</p> <pre><code>public class ResultDelegate implements PayPalResultDelegate, Serializable { public void onPaymentSucceeded(String payKey, String paymentStatus) { System.out.println("SUCCESS, You have successfully completed your transaction."); System.out.println("PayKey: "+payKey); System.out.println("PayStatus: "+paymentStatus); callMyCustomAfterPaymentFunction(); } ... } </code></pre> <p>Now the thing is, I tried to create a constructor for ResultDelegate that accepts my activity. My existing code is:</p> <pre><code>//On the activity class public class MainMenuActivity extends Activity { public void onCreate(Bundle savedInstanceState) { ... Button buy = (Button) findViewByID(R.id.buy_button); buy.setOnClickListener(new View.OnClickListener(){ public void onClick(View v) { new PurchaseTask(activity).execute(); } } } } public class PurchaseTask extends AsyncTask &lt;String, Void, String&gt; { protected String doInBackground() { ... PayPal pp = PayPal.getInstance(); CheckoutButton cb = pp.getCheckoutButton(...); cb.setOnClickListener(new View.OnClickListener(){ public void onClick(View v){ ResultDelegate delegate = new ResultDelegate(myActivity); Intent checkout = PayPal.getInstance().checkout(paument, activity, delegate); activity.StartActivity(checkoutIntent); } } } } //On the ResultDelegate class public class ResultDelegate implements PayPalResultDelegate, Serializable { private Activity myActivity; public void onPaymentSucceeded(String payKey, String paymentStatus) { System.out.println("SUCCESS, You have successfully completed your transaction."); System.out.println("PayKey: "+payKey); System.out.println("PayStatus: "+paymentStatus); myActivity.performAfterPaymentOperations(); } ... } </code></pre> <p>So the goal is to call the activity function from the ResultDelegate. Or even simpler, just to be able to store some SharedPreference changes when the ResultDelegate onPaymentSucceeded() fires.</p> <p>But I get a NotSerializableException mentioning that the my MyActivity field is not Serializable.</p> <p>So, then I added the transient identifier to my activity field inside the ResultDelegate, but now I get a NullPointerException.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload