我在付款时遇到错误总是出现这样的错误,我能够知道哪里是窗口泄漏错误。
这是我的代码
private fun showAlertWithTextInputLayout(context: Context) {
val textInputLayout = TextInputLayout(context)
textInputLayout.setPadding(
resources.getDimensionPixelOffset(R.dimen.dp_19),
0,
resources.getDimensionPixelOffset(R.dimen.dp_19),
0
)
val input = EditText(context)
textInputLayout.hint = "Coin"
input.inputType= InputType.TYPE_CLASS_NUMBER + InputType.TYPE_NUMBER_FLAG_DECIMAL + InputType.TYPE_NUMBER_FLAG_SIGNED
textInputLayout.addView(input)
val alert = AlertDialog.Builder(context)
.setTitle("Add Coins")
.setView(textInputLayout)
.setMessage("How many coin wants to add?")
.setPositiveButton("Add") {
dialog, _ ->
if (!input.text.equals("") ){
launchPayUMoneyFlow(input.text.toString())
}else{
AppLogger.toast("Please enter some value.")
}
dialog.cancel()
}
.setNegativeButton("Cancel") { dialog, _ ->
dialog.cancel()
}.create()
alert.show()
}
private var mAppPreference: AppPreference? = null
private var mPaymentParams: PayUmoneySdkInitializer.PaymentParam? = null
private val isDisableExitConfirmation = false
lateinit var binding: ActivityPaymentBinding
lateinit var usetId:String
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = DataBindingUtil.setContentView(this, R.layout.activity_payment)
initView()
}
private fun initView() {
if(MoodApplication.sharedPreference.getValueUserLogedIn()!=null && MoodApplication.sharedPreference.getValueUserLogedIn()!!.data!!.id!=null ){
usetId = MoodApplication.sharedPreference.getValueUserLogedIn()!!.data!!.id!!
}
mAppPreference = AppPreference()
binding.btnBack.setOnClickListener(this)
binding.cardAddGift.setOnClickListener(this)
binding.cardReceivedGift.setOnClickListener(this)
binding.cardRedeem.setOnClickListener(this)
binding.cardTransctionHistory.setOnClickListener(this)
binding.cardSendGift.setOnClickListener(this)
selectSandBoxEnv()
setupCitrusConfigs()
}
override fun onResume() {
super.onResume()
val points=MoodApplication.sharedPreference.getValueUserLogedIn()!!.data!!.referralpoints
if (points!=null){
binding.tvTotalPonits.text=points
}
}
private fun setupCitrusConfigs() {
val appEnvironment = (application as MoodApplication).getAppEnvironment()
if (appEnvironment === AppEnvironment.PRODUCTION) {
} else {
}
}
private fun selectSandBoxEnv() {
(application as MoodApplication).setAppEnvironment(AppEnvironment.SANDBOX)
setupCitrusConfigs()
}
private fun launchPayUMoneyFlow(payMoney:String) {
val payUmoneyConfig = PayUmoneyConfig.getInstance()
payUmoneyConfig.doneButtonText = "Pay"
payUmoneyConfig.payUmoneyActivityTitle = "Pay :"+payMoney
payUmoneyConfig.disableExitConfirmation(isDisableExitConfirmation)
val builder = PayUmoneySdkInitializer.PaymentParam.Builder()
var amount = 0.0
try {
amount = java.lang.Double.parseDouble(payMoney)
} catch (e: Exception) {
e.printStackTrace()
}
val txnId = System.currentTimeMillis().toString() + ""
//String txnId = "TXNID720431525261327973";
val phone = MoodApplication.sharedPreference.getValueUserLogedIn()!!.data!!.phoneNumber
val productName = mAppPreference!!.productInfo
val firstName = mAppPreference!!.firstName
val email = MoodApplication.sharedPreference.getValueUserLogedIn()!!.data!!.email
val udf1 = ""
val udf2 = ""
val udf3 = ""
val udf4 = ""
val udf5 = ""
val udf6 = ""
val udf7 = ""
val udf8 = ""
val udf9 = ""
val udf10 = ""
val appEnvironment = (application as MoodApplication).getAppEnvironment()
builder.setAmount(amount.toString())
.setTxnId(txnId)
.setPhone(phone)
.setProductName(productName)
.setFirstName(firstName)
.setEmail(email)
.setsUrl(appEnvironment.surl())
.setfUrl(appEnvironment.furl())
.setUdf1(udf1)
.setUdf2(udf2)
.setUdf3(udf3)
.setUdf4(udf4)
.setUdf5(udf5)
.setUdf6(udf6)
.setUdf7(udf7)
.setUdf8(udf8)
.setUdf9(udf9)
.setUdf10(udf10)
.setIsDebug(appEnvironment.debug())
.setKey(appEnvironment.merchant_Key())
.setMerchantId(appEnvironment.merchant_ID())
Log.e("@@MerchantKEy",appEnvironment.merchant_Key() )
Log.e("@@MerchantKEy",appEnvironment.merchant_ID() )
Log.e("@@MerchantKEy",appEnvironment.salt() )
try {
mPaymentParams = builder.build()
mPaymentParams = calculateServerSideHashAndInitiatePayment1(mPaymentParams!!)
if (AppPreference.selectedTheme != -1) {
PayUmoneyFlowManager.startPayUMoneyFlow(mPaymentParams, this@WalletActivity, AppPreference.selectedTheme, mAppPreference!!.isOverrideResultScreen)
} else {
PayUmoneyFlowManager.startPayUMoneyFlow(mPaymentParams, this@WalletActivity, R.style.AppTheme_default, mAppPreference!!.isOverrideResultScreen)
}
} catch (e: Exception) {
Toast.makeText(this, e.message, Toast.LENGTH_LONG).show()
// payNowButton!!.isEnabled = true
}
}
private fun calculateServerSideHashAndInitiatePayment1(paymentParam: PayUmoneySdkInitializer.PaymentParam): PayUmoneySdkInitializer.PaymentParam {
val stringBuilder = StringBuilder()
val params = paymentParam.params
stringBuilder.append(params[PayUmoneyConstants.KEY]!! + "|")
stringBuilder.append(params[PayUmoneyConstants.TXNID]!! + "|")
stringBuilder.append(params[PayUmoneyConstants.AMOUNT]!! + "|")
stringBuilder.append(params[PayUmoneyConstants.PRODUCT_INFO]!! + "|")
stringBuilder.append(params[PayUmoneyConstants.FIRSTNAME]!! + "|")
stringBuilder.append(params[PayUmoneyConstants.EMAIL]!! + "|")
stringBuilder.append(params[PayUmoneyConstants.UDF1]!! + "|")
stringBuilder.append(params[PayUmoneyConstants.UDF2]!! + "|")
stringBuilder.append(params[PayUmoneyConstants.UDF3]!! + "|")
stringBuilder.append(params[PayUmoneyConstants.UDF4]!! + "|")
stringBuilder.append(params[PayUmoneyConstants.UDF5]!! + "||||||")
val appEnvironment = (application as MoodApplication).getAppEnvironment()
stringBuilder.append(appEnvironment.salt())
val hash = Membership.hashCal(stringBuilder.toString())
paymentParam.setMerchantHash(hash)
return paymentParam
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
Log.d("MainActivity", "request code $requestCode resultcode $resultCode")
try {
if (requestCode == PayUmoneyFlowManager.REQUEST_CODE_PAYMENT && resultCode == Activity.RESULT_OK && data != null) {
val transactionResponse = data.getParcelableExtra<TransactionResponse>(PayUmoneyFlowManager
.INTENT_EXTRA_TRANSACTION_RESPONSE)
val resultModel = data.getParcelableExtra<ResultModel>(PayUmoneyFlowManager.ARG_RESULT)
if (transactionResponse != null && transactionResponse.getPayuResponse() != null) {
if (transactionResponse.transactionStatus == TransactionResponse.TransactionStatus.SUCCESSFUL) {
val payuResponse = transactionResponse.getPayuResponse()
var gson: Gson = Gson()
var response = gson.fromJson(payuResponse, PayumoneyResponse::class.java)
Log.e("@@Response", response.toString())
addoinsApi(response.result.amount)
} else {
}
} else if (resultModel != null && resultModel.error != null) {
Log.d(Membership.TAG, "Error response : " + resultModel.error.transactionResponse)
} else {
Log.d(Membership.TAG, "Both objects are null!")
}
}
} catch (e: Exception) {
Toast.makeText(this, e.message, Toast.LENGTH_LONG).show()
}
}
private fun addoinsApi(amount: String) {
AndroidNetworking.post(Constant.BASE_URL + "app.php?api=addCoins")
.addUrlEncodeFormBodyParameter("userid",usetId)
.addUrlEncodeFormBodyParameter("addcoins",amount)
.setTag("addCoins")
.setContentType("application/x-www-form-urlencoded")
.setPriority(Priority.MEDIUM)
.build()
.getAsString(object : StringRequestListener {
override fun onResponse(response: String) {
AppLogger.e("addCoins response","====="+response)
val loginModel: LoginModel? =MoodApplication.sharedPreference.getValueUserLogedIn()
loginModel!!.data!!.referralpoints=(Integer.parseInt(loginModel.data!!.referralpoints.toString())+java.lang.Double.parseDouble(amount).toInt()).toString()
MoodApplication.sharedPreference.saveSigninUser(loginModel)
binding.tvTotalPonits.text=loginModel.data!!.referralpoints
AlertDialog.Builder(this@WalletActivity)
.setCancelable(false)
.setMessage("Coins successfully added.")
.setPositiveButton(android.R.string.ok) {
dialog, whichButton -> dialog.dismiss()
}.show()
}
override fun onError(error: ANError) {
AppLogger.toast(error.localizedMessage)
Log.e(" addCoins Error", "=======" + error.localizedMessage)
}
})
}
}
我遇到了错误,我看到了很多答案,但是我没有得到,所以请帮助我,谢谢你,我会很感激每个答案
错误是
20568-20568/com.example.moods E/WindowManager: android.view.WindowLeaked: Activity com.payumoney.core.SdkWebViewActivityNew has leaked window DecorView@7f9a05a[SdkWebViewActivityNew] that was originally added here
我认为因为出现对话框,首先发生此错误,所以您不使用dialog.dismiss()
来使用dialog.cancel()
,而必须像这样在override onDestroy()
方法和onPause()
方法中关闭对话框。...
@Override
protected void onPause() {
super.onPause();
if(dialog!=null)
dialog.dismiss();
}
@Override
protected void onDestory() {
super.onDestory();
if(dialog!=null)
dialog.dismiss();
}
我希望这项工作...