简体   繁体   English

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

[英]How to store status result in app and get it when app is restarted

how to restore payment status while application is started.ie integrated paypal for app subscription,once app started it shows alert box for payment ,payment completed app going to same screen with out alertbox.if i exit from app and again started(restarted) then i want to get the payment stutus ,bcz i want to display the app screen based on status how to do it.here adding onActivity result 应用程序启动时如何恢复付款状态。应用程序订阅时集成了paypal,一旦应用程序启动,它会显示付款的警报框,付款已完成的应用程序进入同一屏幕而不用alertbox.if我从应用程序退出并再次启动(重新启动)然后我想得到支付stutus,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.");
        }
    }

Use this to get default preferences: 使用此选项可获取默认首选项:

SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);

Use this to save a value: 使用它来保存值:

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

and this to retrieve the value: preferences.getString("isPayed", "No"); 这是为了检索值: preferences.getString("isPayed", "No");

You could try SharedPreferences. 你可以试试SharedPreferences。 Whenever the payment activity is complete set the flag as 1. 每当付款活动完成时,将标志设置为1。

Eg. 例如。

int flag = entry.getInt("flag",0);
if(flag==0)
{
// Payment alert
// Payment finished
// editor.putInt("flag", ++flag);
// editor.commit();
}
else 
{
//Don't display the dialog
}

In this way as the user finishes the payment set the flag as 1. 以这种方式,当用户完成支付时,将标志设置为1。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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