naveridlogin-sdk-android
naveridlogin-sdk-android copied to clipboard
[5.1.0] NidProgressDialog WindowManager$BadTokenException
SDK 5.1.0
해당 이슈와 동일한 이슈가 발생합니다.
android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy@4ee548e is not valid; is your activity running?
at android.view.ViewRootImpl.setView(ViewRootImpl.java:1147)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:471)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:95)
at android.app.Dialog.show(Dialog.java:507)
at ma.a.showProgress(NidProgressDialog.kt:8)
at ma.a.showProgress(NidProgressDialog.kt:3)
at ma.a.showProgress(NidProgressDialog.kt:1)
at da.f$b.invokeSuspend(NidOAuthLogin.kt:4)
at kotlin.coroutines.jvm.internal.a.resumeWith(ContinuationImpl.kt:4)
at kotlinx.coroutines.z0.run(DispatchedTask.kt:18)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:237)
at android.app.ActivityThread.main(ActivityThread.java:8154)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)
이것이 잘못된 usage 때문인지는 모르겠지만, NidProgressDialog
내부의 AppCompatDialog
를 show
할 때, 방어 로직이 들어가면 좋을 것 같습니다.
package com.navercorp.nid.progress
import android.app.Activity
import android.content.Context
import android.content.DialogInterface
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import androidx.appcompat.app.AppCompatDialog
import androidx.appcompat.widget.AppCompatTextView
import com.airbnb.lottie.LottieAnimationView
import com.nhn.android.oauth.R
/**
*
* Created on 2021.10.22
* Updated on 2021.10.22
*
* @author Namhoon Kim. ([email protected])
* Naver Authentication Platform Development.
*
* 네이버 공통 Nid Progress Dialog
*/
class NidProgressDialog {
private var context: Context
private var dialog: AppCompatDialog
private var message: AppCompatTextView? = null
private var animation: LottieAnimationView? = null
constructor(context: Context) {
this.context = context
this.dialog = AppCompatDialog(context)
init(null)
}
private val isSafeForManipulateDialogVisibility get() = (context as? Activity)?.isFinishing != true
private fun init(cancelListener: DialogInterface.OnCancelListener?) {
dialog.setCancelable(true)
dialog.window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
dialog.setContentView(R.layout.nid_progress_dialog)
message = dialog.findViewById(R.id.nid_progress_dialog_message)
animation = dialog.findViewById(R.id.nid_progress_dialog_animation)
}
fun showProgress(resourceId: Int) {
showProgress(context.resources.getString(resourceId))
}
fun showProgress(resourceId: Int, cancelListener: DialogInterface.OnCancelListener? = null) {
showProgress(context.resources.getString(resourceId), cancelListener)
}
fun showProgress(msg: String) {
showProgress(msg, null)
}
fun showProgress(msg: String, cancelListener: DialogInterface.OnCancelListener? = null) {
message?.let {
it.text = msg
}
cancelListener?.let {
dialog.setOnCancelListener(cancelListener)
}
animation?.playAnimation()
if (isSafeForManipulateDialogVisibility) {
dialog.show()
}
}
fun hideProgress() {
if (dialog.isShowing && isSafeForManipulateDialogVisibility) {
animation?.pauseAnimation()
dialog.dismiss()
}
}
}