Open syxc opened 7 months ago
加了几句代码,以防部分情况下使用不当造成内存泄露,仅供参考。
private val mContext = context override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.layout_bubble_dialog) tvTitle = findViewById(R.id.tv_title) tvTitle?.text = title val rotateDrawable = findViewById<ImageView>(R.id.iv_loading).background as RotateDrawable ObjectAnimator.ofInt(rotateDrawable, "level", 0, 10000).apply { duration = 2000 repeatCount = ValueAnimator.INFINITE interpolator = LinearInterpolator() start() } (mContext as? ComponentActivity)?.lifecycle?.addObserver( object : LifecycleObserver { @OnLifecycleEvent(Lifecycle.Event.ON_STOP) fun onStop() { if (isShowing) { dismiss() Log.d("BubbleDialog", "---onStop dismiss---") } } @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY) fun onDestroy() { if (isShowing) { dismiss() Log.d("BubbleDialog", "---onDestroy dismiss---") } } }, ) }
加了几句代码,以防部分情况下使用不当造成内存泄露,仅供参考。