[英]How to store status result in app and get it when app is restarted
應用程序啟動時如何恢復付款狀態。應用程序訂閱時集成了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.");
}
}
使用此選項可獲取默認首選項:
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
使用它來保存值:
Editor edit = preferences.edit();
edit.putString("isPayed", "yes");
edit.apply();
這是為了檢索值: preferences.getString("isPayed", "No");
你可以試試SharedPreferences。 每當付款活動完成時,將標志設置為1。
例如。
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
}
以這種方式,當用戶完成支付時,將標志設置為1。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.