简体   繁体   中英

Performance issue with Android PayPal button

I am making a Android application that accepts donations via PayPal. Everything is working fine as far as functionality. However, when I launch my donation activity, it takes about 6-7 seconds to finally open. I don't know why. Could it be that I am programatically adding the PayPal CheckoutButton to my layout instead of adding it in xml?

Here is how I am adding the button:

    // PayPal Button
    PayPal ppObj = PayPal.initWithAppID(this, "APP-ID", PayPal.ENV_LIVE);
    CheckoutButton launchPayPalButton = ppObj.getCheckoutButton(this, PayPal.BUTTON_278x43, CheckoutButton.TEXT_DONATE);
    launchPayPalButton.setOnClickListener(this);

    // Place PayPal Button in Layout
    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    params.addRule(RelativeLayout.ALIGN_PARENT_TOP);
    params.addRule(RelativeLayout.CENTER_HORIZONTAL);
    params.topMargin = 10;
    launchPayPalButton.setLayoutParams(params);
    ((RelativeLayout)findViewById(R.id.donateRelativeLayout)).addView(launchPayPalButton);

Is there a way to do this in xml? And is this even the reason for the performance issue?

If clicking on the donate button executes code which does some lengthy operations like network connections in the UI thread (event thread), it will slow the UI. The lag you are seeing might be because you are doing network connection on the UI thread (event thread). Move the operations into a separate thread and see if that solves the issue?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM