Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8152347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:41:11+00:00 2026-06-06T15:41:11+00:00

I have seen some related questions but none focusing on the specific problem I

  • 0

I have seen some related questions but none focusing on the specific problem I have:

I’m using the PayPal MPL Library.

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.).

So something like this:

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();
    }
    ...
}

Now the thing is, I tried to create a constructor for ResultDelegate that accepts my activity. My existing code is:

//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 <String, Void, String> {
    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();
    }
    ...
}

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.

But I get a NotSerializableException mentioning that the my MyActivity field is not Serializable.

So, then I added the transient identifier to my activity field inside the ResultDelegate, but now I get a NullPointerException.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T15:41:12+00:00Added an answer on June 6, 2026 at 3:41 pm

    Paypal Mobile Chekout guide

    Implementation provided on paypal website is different from yours. They are doing startActivityForResult() to start PaypalActivity. and when in onActivityResult() method they are checking statusCode to check transaction status and act accordingly.

    Follow that document for your implementation.

    Here in your code, I donot find a point for using AsyncTask. Your ResultDelegate is Serializable where as Activity is not thats why it is throwing NotSerializableException.

    Edit:

    As you are developing for Google Android platform, then why not to use Google Checkout In-App?

    Edit:

    This method will be called when your PaypalActivity will finish. That activity will pass resultCode to this onActivityResult method.

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        switch (resultCode) {
        case Activity.RESULT_OK:
            // The payment succeeded
            String payKey = data.getStringExtra(PayPalActivity.EXTRA_PAY_KEY);
            // Tell the user their payment succeeded
            break;
        case Activity.RESULT_CANCELED:
            // The payment was canceled
            // Tell the user their payment was canceled
            break;
        case PayPalActivity.RESULT_FAILURE:
            // The payment failed -- we get the error from the EXTRA_ERROR_ID
            // and EXTRA_ERROR_MESSAGE
            String errorID = data.getStringExtra(PayPalActivity.EXTRA_ERROR_ID);
            String errorMessage = data
                    .getStringExtra(PayPalActivity.EXTRA_ERROR_MESSAGE);
            // Tell the user their payment was failed.
        }
    }
    

    regards,
    Aqif Hamid

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have seen some other questions about this but the errors were related to
Hi all I have seen all question related to this problem but couldn't find
I have looked at the other questions related to this problem but I do
Have seen some similar questions: What is the difference between a JavaBean and a
i have seen some hand rolled solutions but does jquery out of the box
I have seen some of the other answers on this topic but dont really
I have seen some demos about the jQuery wizard plugin on websites. But all
I saw some results via the related questions but didn't actually seem to show
I've seen a few questions related to API specifics and paypal. Generally speaking if
I've seen a few related questions posted like two years ago, but I would

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.