Check whether activity is active

前端 未结 8 2276
眼角桃花
眼角桃花 2020-11-27 04:47

I\'m having a problem with a listener in a certain activity.

The problem is that this listener contains an alert.show(); which can be called after we try to push a

8条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-27 05:20

    This happens when the Activity will be going through its destruction when the background thread finishes its work and tries to show a Dialog.

    This exeption is rare to reproduce but happens when we do some async task / background operation and want to display a dialog with Activity context and in the mean while our activity is destroying itself due to some reason.

    Android OS should handle this situation, but as of now it does not.

    so before calling your dialog just check if activity is running and not in its destruction phase.

    if(!isFinishing()){
     callDialog();
    }
    

提交回复
热议问题