Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/360.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 正在停止未恢复的活动_Java_Android_Android Activity_Paypal_Parse Platform - Fatal编程技术网

Java 正在停止未恢复的活动

Java 正在停止未恢复的活动,java,android,android-activity,paypal,parse-platform,Java,Android,Android Activity,Paypal,Parse Platform,我意外地遇到了以下问题: 正在停止未恢复的活动 我主要致力于将paypal SDK集成到应用程序中。特别是,我认为错误源于以下尝试: 我试图根据Parse.com中存储的信息生成价格和商品名称 private PayPalPayment getThingToBuy(String paymentIntent) { return new PayPalPayment(new BigDecimal("mActivityPrice"), "USD", "mActivityName",

我意外地遇到了以下问题: 正在停止未恢复的活动

我主要致力于将paypal SDK集成到应用程序中。特别是,我认为错误源于以下尝试:

我试图根据Parse.com中存储的信息生成价格和商品名称

   private PayPalPayment getThingToBuy(String paymentIntent) {
        return new PayPalPayment(new BigDecimal("mActivityPrice"), "USD", "mActivityName",
                paymentIntent);
    }
mActivityPrice和mActivityName来自哪里

  String mActivityPrice = ParseUser.getCurrentUser().getString("ActivityPrice");
    String mActivityName = ParseUser.getCurrentUser().getString("ActivityName");
日志cat消息:

09-16 19:47:52.494: E/ActivityThread(1679): Performing stop of activity that is not resumed: {com.paypal.example.paypalandroidsdkexample/com.paypal.android.sdk.payments.PaymentMethodActivity}
09-16 19:47:52.494: E/ActivityThread(1679): java.lang.RuntimeException: Performing stop of activity that is not resumed: {com.paypal.example.paypalandroidsdkexample/com.paypal.android.sdk.payments.PaymentMethodActivity}
09-16 19:47:52.494: E/ActivityThread(1679):     at android.app.ActivityThread.performStopActivityInner(ActivityThread.java:3147)
09-16 19:47:52.494: E/ActivityThread(1679):     at android.app.ActivityThread.handleStopActivity(ActivityThread.java:3234)
09-16 19:47:52.494: E/ActivityThread(1679):     at android.app.ActivityThread.access$1100(ActivityThread.java:135)
09-16 19:47:52.494: E/ActivityThread(1679):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1223)
09-16 19:47:52.494: E/ActivityThread(1679):     at android.os.Handler.dispatchMessage(Handler.java:102)
09-16 19:47:52.494: E/ActivityThread(1679):     at android.os.Looper.loop(Looper.java:136)
09-16 19:47:52.494: E/ActivityThread(1679):     at android.app.ActivityThread.main(ActivityThread.java:5017)
09-16 19:47:52.494: E/ActivityThread(1679):     at java.lang.reflect.Method.invokeNative(Native Method)
09-16 19:47:52.494: E/ActivityThread(1679):     at java.lang.reflect.Method.invoke(Method.java:515)
09-16 19:47:52.494: E/ActivityThread(1679):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
09-16 19:47:52.494: E/ActivityThread(1679):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
09-16 19:47:52.494: E/ActivityThread(1679):     at dalvik.system.NativeStart.main(Native Method)
以下是活动代码:

public class PayPalPaymentActivity extends Activity {
    private static final String TAG = "paymentExample";
    String mActivityPrice = ParseUser.getCurrentUser().getString("ActivityPrice");
    String mActivityName = ParseUser.getCurrentUser().getString("ActivityName");


    /**
     * - Set to PaymentActivity.ENVIRONMENT_PRODUCTION to move real money.
     * 
     * - Set to PaymentActivity.ENVIRONMENT_SANDBOX to use your test credentials
     * from https://developer.paypal.com
     * 
     * - Set to PayPalConfiguration.ENVIRONMENT_NO_NETWORK to kick the tires
     * without communicating to PayPal's servers.
     */
    private static final String CONFIG_ENVIRONMENT = PayPalConfiguration.ENVIRONMENT_NO_NETWORK;

    // note that these credentials will differ between live & sandbox environments.
    private static final String CONFIG_CLIENT_ID = "credential from developer.paypal.com";

    private static final int REQUEST_CODE_PAYMENT = 1;
    private static final int REQUEST_CODE_FUTURE_PAYMENT = 2;
    private static final int REQUEST_CODE_PROFILE_SHARING = 3;

    private static PayPalConfiguration config = new PayPalConfiguration()
            .environment(CONFIG_ENVIRONMENT)
            .clientId(CONFIG_CLIENT_ID)
            // The following are only used in PayPalFuturePaymentActivity.
            .merchantName("Hipster Store")
            .merchantPrivacyPolicyUri(Uri.parse("https://www.example.com/privacy"))
            .merchantUserAgreementUri(Uri.parse("https://www.example.com/legal"));

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.paypalpayment_layout);

        Intent intent = new Intent(this, PayPalService.class);
        intent.putExtra(PayPalService.EXTRA_PAYPAL_CONFIGURATION, config);
        startService(intent);
    }

    public void onBuyPressed(View pressed) {
        /* 
         * PAYMENT_INTENT_SALE will cause the payment to complete immediately.
         * Change PAYMENT_INTENT_SALE to 
         *   - PAYMENT_INTENT_AUTHORIZE to only authorize payment and capture funds later.
         *   - PAYMENT_INTENT_ORDER to create a payment for authorization and capture
         *     later via calls from your server.
         * 
         * Also, to include additional payment details and an item list, see getStuffToBuy() below.
         */
        PayPalPayment thingToBuy = getThingToBuy(PayPalPayment.PAYMENT_INTENT_SALE);

        /*
         * See getStuffToBuy(..) for examples of some available payment options.
         */

        Intent intent = new Intent(PayPalPaymentActivity.this, PaymentActivity.class);

        intent.putExtra(PaymentActivity.EXTRA_PAYMENT, thingToBuy);

        startActivityForResult(intent, REQUEST_CODE_PAYMENT);
    }

    private PayPalPayment getThingToBuy(String paymentIntent) {
        return new PayPalPayment(new BigDecimal("mActivityPrice"), "USD", "mActivityName",
                paymentIntent);
    }

    /* 
     * This method shows use of optional payment details and item list.
     */
    private PayPalPayment getStuffToBuy(String paymentIntent) {
        //--- include an item list, payment amount details
        PayPalItem[] items =
            {
                    new PayPalItem("old jeans with holes", 2, new BigDecimal("87.50"), "USD",
                            "sku-12345678"),
                    new PayPalItem("free rainbow patch", 1, new BigDecimal("0.00"),
                            "USD", "sku-zero-price"),
                    new PayPalItem("long sleeve plaid shirt (no mustache included)", 6, new BigDecimal("37.99"),
                            "USD", "sku-33333") 
            };
        BigDecimal subtotal = PayPalItem.getItemTotal(items);
        BigDecimal shipping = new BigDecimal("7.21");
        BigDecimal tax = new BigDecimal("4.67");
        PayPalPaymentDetails paymentDetails = new PayPalPaymentDetails(shipping, subtotal, tax);
        BigDecimal amount = subtotal.add(shipping).add(tax);
        PayPalPayment payment = new PayPalPayment(amount, "USD", "hipster jeans", paymentIntent);
        payment.items(items).paymentDetails(paymentDetails);

        //--- set other optional fields like invoice_number, custom field, and soft_descriptor
        payment.custom("This is text that will be associated with the payment that the app can use.");

        return payment;
    }

    /*
     * Add app-provided shipping address to payment
     */
    private void addAppProvidedShippingAddress(PayPalPayment paypalPayment) {
        ShippingAddress shippingAddress =
                new ShippingAddress().recipientName("Mom Parker").line1("52 North Main St.")
                        .city("Austin").state("TX").postalCode("78729").countryCode("US");
        paypalPayment.providedShippingAddress(shippingAddress);
    }

    /*
     * Enable retrieval of shipping addresses from buyer's PayPal account
     */
    private void enableShippingAddressRetrieval(PayPalPayment paypalPayment, boolean enable) {
        paypalPayment.enablePayPalShippingAddressesRetrieval(enable);
    }

    public void onFuturePaymentPressed(View pressed) {
        Intent intent = new Intent(PayPalPaymentActivity.this, PayPalFuturePaymentActivity.class);

        startActivityForResult(intent, REQUEST_CODE_FUTURE_PAYMENT);
    }

    public void onProfileSharingPressed(View pressed) {
        Intent intent = new Intent(PayPalPaymentActivity.this, PayPalProfileSharingActivity.class);
        intent.putExtra(PayPalProfileSharingActivity.EXTRA_REQUESTED_SCOPES, getOauthScopes());
        startActivityForResult(intent, REQUEST_CODE_PROFILE_SHARING);
    }

    private PayPalOAuthScopes getOauthScopes() {
        /* create the set of required scopes
         * Note: see https://developer.paypal.com/docs/integration/direct/identity/attributes/ for mapping between the
         * attributes you select for this app in the PayPal developer portal and the scopes required here.
         */
        Set<String> scopes = new HashSet<String>(
                Arrays.asList(PayPalOAuthScopes.PAYPAL_SCOPE_EMAIL, PayPalOAuthScopes.PAYPAL_SCOPE_ADDRESS) );
        return new PayPalOAuthScopes(scopes);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == REQUEST_CODE_PAYMENT) {
            if (resultCode == Activity.RESULT_OK) {
                PaymentConfirmation confirm =
                        data.getParcelableExtra(PaymentActivity.EXTRA_RESULT_CONFIRMATION);
                if (confirm != null) {
                    try {
                        Log.i(TAG, confirm.toJSONObject().toString(4));
                        Log.i(TAG, confirm.getPayment().toJSONObject().toString(4));
                        /**
                         *  TODO: send 'confirm' (and possibly confirm.getPayment() to your server for verification
                         * or consent completion.
                         * See https://developer.paypal.com/webapps/developer/docs/integration/mobile/verify-mobile-payment/
                         * for more details.
                         *
                         * For sample mobile backend interactions, see
                         * https://github.com/paypal/rest-api-sdk-python/tree/master/samples/mobile_backend
                         */
                        Toast.makeText(
                                getApplicationContext(),
                                "PaymentConfirmation info received from PayPal", Toast.LENGTH_LONG)
                                .show();

                    } catch (JSONException e) {
                        Log.e(TAG, "an extremely unlikely failure occurred: ", e);
                    }
                }
            } else if (resultCode == Activity.RESULT_CANCELED) {
                Log.i(TAG, "The user canceled.");
            } else if (resultCode == PaymentActivity.RESULT_EXTRAS_INVALID) {
                Log.i(
                        TAG,
                        "An invalid Payment or PayPalConfiguration was submitted. Please see the docs.");
            }
        } else if (requestCode == REQUEST_CODE_FUTURE_PAYMENT) {
            if (resultCode == Activity.RESULT_OK) {
                PayPalAuthorization auth =
                        data.getParcelableExtra(PayPalFuturePaymentActivity.EXTRA_RESULT_AUTHORIZATION);
                if (auth != null) {
                    try {
                        Log.i("FuturePaymentExample", auth.toJSONObject().toString(4));

                        String authorization_code = auth.getAuthorizationCode();
                        Log.i("FuturePaymentExample", authorization_code);

                        sendAuthorizationToServer(auth);
                        Toast.makeText(
                                getApplicationContext(),
                                "Future Payment code received from PayPal", Toast.LENGTH_LONG)
                                .show();

                    } catch (JSONException e) {
                        Log.e("FuturePaymentExample", "an extremely unlikely failure occurred: ", e);
                    }
                }
            } else if (resultCode == Activity.RESULT_CANCELED) {
                Log.i("FuturePaymentExample", "The user canceled.");
            } else if (resultCode == PayPalFuturePaymentActivity.RESULT_EXTRAS_INVALID) {
                Log.i(
                        "FuturePaymentExample",
                        "Probably the attempt to previously start the PayPalService had an invalid PayPalConfiguration. Please see the docs.");
            } 
        } else if (requestCode == REQUEST_CODE_PROFILE_SHARING) {
            if (resultCode == Activity.RESULT_OK) {
                PayPalAuthorization auth =
                        data.getParcelableExtra(PayPalProfileSharingActivity.EXTRA_RESULT_AUTHORIZATION);
                if (auth != null) {
                    try {
                        Log.i("ProfileSharingExample", auth.toJSONObject().toString(4));

                        String authorization_code = auth.getAuthorizationCode();
                        Log.i("ProfileSharingExample", authorization_code);

                        sendAuthorizationToServer(auth);
                        Toast.makeText(
                                getApplicationContext(),
                                "Profile Sharing code received from PayPal", Toast.LENGTH_LONG)
                                .show();

                    } catch (JSONException e) {
                        Log.e("ProfileSharingExample", "an extremely unlikely failure occurred: ", e);
                    }
                }
            } else if (resultCode == Activity.RESULT_CANCELED) {
                Log.i("ProfileSharingExample", "The user canceled.");
            } else if (resultCode == PayPalFuturePaymentActivity.RESULT_EXTRAS_INVALID) {
                Log.i(
                        "ProfileSharingExample",
                        "Probably the attempt to previously start the PayPalService had an invalid PayPalConfiguration. Please see the docs.");
            }
        }
    }

    private void sendAuthorizationToServer(PayPalAuthorization authorization) {

        /**
         * TODO: Send the authorization response to your server, where it can
         * exchange the authorization code for OAuth access and refresh tokens.
         * 
         * Your server must then store these tokens, so that your server code
         * can execute payments for this user in the future.
         * 
         * A more complete example that includes the required app-server to
         * PayPal-server integration is available from
         * https://github.com/paypal/rest-api-sdk-python/tree/master/samples/mobile_backend
         */

    }

    public void onFuturePaymentPurchasePressed(View pressed) {
        // Get the Application Correlation ID from the SDK
        String correlationId = PayPalConfiguration.getApplicationCorrelationId(this);

        Log.i("FuturePaymentExample", "Application Correlation ID: " + correlationId);

        // TODO: Send correlationId and transaction details to your server for processing with
        // PayPal...
        Toast.makeText(
                getApplicationContext(), "App Correlation ID received from SDK", Toast.LENGTH_LONG)
                .show();
    }

    @Override
    public void onDestroy() {
        // Stop service when done
        stopService(new Intent(this, PayPalService.class));
        super.onDestroy();
    }
}
公共类PayPalPaymentActivity扩展活动{
私有静态最终字符串TAG=“paymentExample”;
字符串mActivityPrice=ParseUser.getCurrentUser().getString(“ActivityPrice”);
字符串mActivityName=ParseUser.getCurrentUser().getString(“ActivityName”);
/**
*-设置为PaymentActivity.ENVIRONMENT\u PRODUCTION以移动实际资金。
* 
*-设置为PaymentActivity.ENVIRONMENT\u SANDBOX以使用您的测试凭据
*从https://developer.paypal.com
* 
*-设置为PayPalConfiguration.ENVIRONMENT\u NO\u NETWORK以启动轮胎
*没有与PayPal的服务器通信。
*/
私有静态最终字符串CONFIG_ENVIRONMENT=PayPalConfiguration.ENVIRONMENT_NO_NETWORK;
//请注意,这些凭据在实时环境和沙盒环境之间会有所不同。
私有静态最终字符串CONFIG_CLIENT_ID=“credential from developer.paypal.com”;
私人静态最终整数请求\代码\付款=1;
私人静态最终整数请求\代码\未来\付款=2;
私有静态最终整数请求\代码\配置文件\共享=3;
私有静态PayPalConfiguration=new PayPalConfiguration()
.environment(配置_环境)
.clientId(配置客户端ID)
//以下内容仅用于PayPalFuturePaymentActivity。
.merchantName(“Hipster商店”)
.merchantPrivacyPolicyUri(Uri.parse(“https://www.example.com/privacy"))
.merchantUserAgreementUri(Uri.parse(“https://www.example.com/legal"));
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(右布局、paypalpayment_布局);
Intent Intent=新Intent(这个,PayPalService.class);
intent.putExtra(PayPalService.EXTRA\u PAYPAL\u配置,config);
startService(意向);
}
已按BuyPressed(按视图)显示公共无效信息{
/* 
*付款意向销售将导致付款立即完成。
*将付款\意向\销售更改为
*-支付\意图\授权仅授权支付并在以后获取资金。
*-付款意向订单,用于创建用于授权和捕获的付款
*稍后通过服务器的呼叫。
* 
*另外,要包含其他付款详细信息和项目列表,请参见下面的getStuffToBuy()。
*/
PayPalPayment thingToBuy=getThingToBuy(PayPalPayment.PAYMENT\u INTENT\u SALE);
/*
*有关一些可用付款选项的示例,请参见getStuffToBuy(..)。
*/
意向意向=新意向(PayPalPaymentActivity.this,PaymentActivity.class);
意向。额外支付(PaymentActivity.EXTRA_PAYMENT,thingToBuy);
startActivityForResult(意向、请求、代码、付款);
}
私人PayPayment getThingToBuy(字符串paymentIntent){
返回新的PayPayment(新的BigDecimal(“mActivityPrice”)、“USD”、“mActivityName”,
支付意向);
}
/* 
*此方法显示可选付款详细信息和项目列表的使用。
*/
私人PayPalPayment getStuffToBuy(字符串paymentIntent){
//---包括项目列表、付款金额详细信息
工资项目[]项目=
{
新PayPalItem(“带洞的旧牛仔裤”,2,新的BigDecimal(“87.50”),“美元”,
“sku-12345678”),
新PayPalItem(“免费彩虹补丁”,1,新BigDecimal(“0.00”),
“美元”、“sku零价格”),
新款PayPalItem(“长袖格子衬衫(不含胡子)”,6款,新款BigDecimal(“37.99”),
“美元”、“sku-33333”)
};
BigDecimal小计=PayPalItem.getItemTotal(项目);
BigDecimal shipping=新的BigDecimal(“7.21”);
BigDecimal税=新的BigDecimal(“4.67”);
PayPalPaymentDetails paymentDetails=新的PayPalPaymentDetails(运费、小计、税金);
BigDecimal金额=小计。添加(装运)。添加(税务);
PayPalPayment付款=新的PayPalPayment(金额,“美元”,“时髦牛仔裤”,paymentIntent);
付款。项目。付款明细(付款明细);
//---设置其他可选字段,如发票号、自定义字段和软描述符
payment.custom(“这是将与应用程序可以使用的付款关联的文本”);
退还款项;
}
/*
*将应用程序提供的发货地址添加到付款
*/
私有void addAppProvidedShippingAddress(PayPalPayment PayPalPayment){
发货地址发货地址=
新发货地址().recipientName(“Mom Parker”).line1(“北大街52号”)
市(“奥斯汀”)。州(“德克萨斯”)。邮政编码(“78729”)。国家代码(“美国”);
paypalPayment.提供的发货地址(发货地址);
}
/*
*启用从买家的PayPal帐户检索发货地址
*/
私有void启用ShippingAddressRetrieval(PayPalPayment PayPalPayment,布尔启用){
paypalPayment.EnablePayPalsShippingAddresssRetrieval(启用);
}
按“未来付款”的公共作废按钮(按“查看”按钮){
意向意向=新意向(PayPalPaymentActivity.this,PayPalFuturePaymentActivity.class);
startActivityForResult(意向、请求、代码、未来付款);
}
在ProfileSharingPressed上公共作废(按视图){
意向意向=新意向(PayPalPaymentA)
private PayPalPayment getThingToBuy(String paymentIntent) {
    String mActivityPrice = "1.25";
    String mActivityName = "The Activity Name";
    return new PayPalPayment(new BigDecimal(mActivityPrice), "USD", mActivityName,
            paymentIntent);
}