仅初始化一次 paypal

发布于 2024-12-09 14:06:45 字数 1219 浏览 0 评论 0原文

我在我的项目中设计了 PayPal 功能,如下所示:

public class MypaypalActivity extends Activity implements OnClickListener{

    /** Called when the activity is first created. */
    @Override

public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        LinearLayout mLinLay= new LinearLayout(this);

        setContentView(R.layout.main);

        PayPal pp = PayPal.initWithAppID(this, "APP-

80W284485P519543T",PayPal.ENV_SANDBOX);


        LinearLayout layoutSimplePayment = new LinearLayout(this);

        layoutSimplePayment.setLayoutParams(new LayoutParams(

                LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

        layoutSimplePayment.setOrientation(LinearLayout.VERTICAL);

        CheckoutButton launchSimplePayment = pp.getCheckoutButton(this,

                PayPal.BUTTON_118x24, CheckoutButton.TEXT_PAY);

        launchSimplePayment.setOnClickListener( this);

        layoutSimplePayment.addView(launchSimplePayment);

        mLinLay.addView(layoutSimplePayment);

        setContentView(mLinLay);

    }

这只可以正常工作一次。当我第二次按下 PayPal 按钮时,该应用程序崩溃了。 catlog中有一个错误是你初始化了PayPal两次,所以使用getInstance();初始化后。

为此我该怎么办?

I have designed PayPal functionality in my project like this:

public class MypaypalActivity extends Activity implements OnClickListener{

    /** Called when the activity is first created. */
    @Override

public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        LinearLayout mLinLay= new LinearLayout(this);

        setContentView(R.layout.main);

        PayPal pp = PayPal.initWithAppID(this, "APP-

80W284485P519543T",PayPal.ENV_SANDBOX);


        LinearLayout layoutSimplePayment = new LinearLayout(this);

        layoutSimplePayment.setLayoutParams(new LayoutParams(

                LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

        layoutSimplePayment.setOrientation(LinearLayout.VERTICAL);

        CheckoutButton launchSimplePayment = pp.getCheckoutButton(this,

                PayPal.BUTTON_118x24, CheckoutButton.TEXT_PAY);

        launchSimplePayment.setOnClickListener( this);

        layoutSimplePayment.addView(launchSimplePayment);

        mLinLay.addView(layoutSimplePayment);

        setContentView(mLinLay);

    }

This will work very correctly only once. When I press the PayPal button a second time then this application crashes. There is an error in catlog is that you initialized PayPal twice, so use getInstance(); after initialization.

What should I do for this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

别闹i 2024-12-16 14:06:45

嘿,这是我的问题的解决方案,我自己完成了这个。

PayPal pp = PayPal.getInstance();
        if (pp == null) {
            try {
                pp = PayPal.initWithAppID(this, "", PayPal.ENV_NONE);
            } catch (IllegalStateException e) {
                throw new RuntimeException(e);
            }
            pp.setShippingEnabled(false);
        }

谢谢大家...

Hey this is solution for my question, i have done this by myself.

PayPal pp = PayPal.getInstance();
        if (pp == null) {
            try {
                pp = PayPal.initWithAppID(this, "", PayPal.ENV_NONE);
            } catch (IllegalStateException e) {
                throw new RuntimeException(e);
            }
            pp.setShippingEnabled(false);
        }

thank you all...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文