android - 如何在应用程序中存储状态结果并在应用程序重新启动时获取它

标签 android paypal

如何在应用程序启动时恢复付款状态。即集成 Paypal 用于应用程序订阅,一旦应用程序启动它会显示付款警告框,付款完成应用程序将进入同一屏幕但没有警告框。如果我退出应用程序并再次启动(重新启动)然后我想获得付款状态,bcz 我想根据状态显示应用程序屏幕如何做。这里添加 onActivity 结果

   @Override
    protected void onActivityResult (int requestCode, int resultCode, Intent data) {
        if (resultCode == Activity.RESULT_OK) {
            PaymentConfirmation confirm = data.getParcelableExtra(PaymentActivity.EXTRA_RESULT_CONFIRMATION);
            if (confirm != null) {
                try {

                    status_result=true;
                    Log.i("paymentExample", confirm.toJSONObject().toString(4));

                    // TODO: send 'confirm' to your server for verification.
                    // see https://developer.paypal.com/webapps/developer/docs/integration/mobile/verify-mobile-payment/
                    // for more details.

                } catch (JSONException e) {
                    Log.e("paymentExample", "an extremely unlikely failure occurred: ", e);
                }
            }
        }
        else if (resultCode == Activity.RESULT_CANCELED) {
            Log.i("paymentExample", "The user canceled.");
        }
        else if (resultCode == PaymentActivity.RESULT_PAYMENT_INVALID) {
            Log.i("paymentExample", "An invalid payment was submitted. Please see the docs.");
        }
    }

最佳答案

使用它来获取默认首选项:

SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);

使用它来保存一个值:

Editor edit = preferences.edit();
edit.putString("isPayed", "yes");
edit.apply(); 

这是检索值:preferences.getString("isPayed", "No");

关于android - 如何在应用程序中存储状态结果并在应用程序重新启动时获取它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19596702/

相关文章:

javascript - 单击图像上的放大弹出窗口在浏览器中打开

java - 从 tabhost 中删除选项卡会导致应用程序崩溃

php - 使用交易ID获取交易详情

java - 在运行时从数组列表中添加和删除用户并保留项目详细信息

java - Android:Android 应用程序中的所有 Activity 是在同一个线程中运行还是在它们自己的单独线程中运行?

codeigniter - CodeIgniter 中的 Paypal Express Checkout

php - 即将到来的 SHA-256 : Do I need to update my IPN listener that does not use a secure URL?

php - App内paypal的实现

android - 构建android源代码时出错

php - Paypal 错误 : user is not allowed to perform this action