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 8785465
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:22:06+00:00 2026-06-13T21:22:06+00:00

I used PayPal SDK before in my regular apps. Here are the steps I

  • 0

I used PayPal SDK before in my regular apps. Here are the steps I take in a normal activity

a) on activity’s onCreate I make a new thread to init the PayPal library

b) if the init goes well, I create a PayPal button and add it in one of my layouts

c) on PayPal button’s onClick I start a new activity for result where the user makes the payment

d) on activity’s onActivityResult I check if payment was successfully and save the info

This worked well so far but things get messy when I try to use the same approach on a fragment. My fragment has a layout with 2 EditTexts and a LinearLayout that will host the Paypal button

So far I did it like this:

@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        context = (MainActivity) getActivity();
        View view = inflater.inflate(R.layout.fragment_layout, container, false);

        libraryInitializationThread = new Thread() {
                @Override
                public void run() {
                    initLibrary();
                    // The library is initialized so let's create our CheckoutButton and update the UI.
                    if (PayPal.getInstance().isLibraryInitialized()) {
                        hRefresh.sendEmptyMessage(INITIALIZE_SUCCESS);
                    } else {
                        hRefresh.sendEmptyMessage(INITIALIZE_FAILURE);
                    }
                }
            };
            libraryInitializationThread.start();
}

private void initLibrary() {
        PayPal pp = PayPal.getInstance();

        if (pp == null) {
            pp = PayPal.initWithAppID(context, getString(R.string.paypal_sandbox_id), PayPal.ENV_SANDBOX);
            pp.setLanguage("en_US"); // Sets the language for the library.
            pp.setDynamicAmountCalculationEnabled(false);
        }
    }

So far, on pp = PayPal.initWithAppID I get this error:

java.lang.IllegalStateException: Fragment FragmentPayPal{415f43f8} not attached to Activity

Now my questions are:

  • where and how should I init the paypal library ?

  • from my fragment, can I start an activity for result and catch onActivityResult ?

Thank you.

  • 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-13T21:22:07+00:00Added an answer on June 13, 2026 at 9:22 pm

    Actually the approach I used in the end was, simply, init paypal library before adding the fragment, in my main hosting activity. In this way it works just fine.

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

Sidebar

Related Questions

I used paypal IPN before to add the payments to a database, but now
I am trying to implement a simple subscribe button using Paypal. I have used
i used this code: List<string> lists=new List<string>(apple,orange,banana,apple,mang0,orange); string names; names=lists.Distinct() is that correct?
how pass multiple values to paypal. I used it in paypal submission page <input
I am trying to implement PayPal into our website. I used cURL to interact
the dropdown is used in my paypal button: <input type=hidden name=on0 value=Type>Type of sauce
I used to have a Buy Now button that would go through PayPal, and
I'm trying to integrate PayPal payments pro express checkout. I've used the following code:
This works now for those new to this question: class ensureparams(object): Used as a
I used to use the paypal form variable to post shipping value to paypal

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.