Close the current activity when you only have a reference to Context

前端 未结 7 1638
暗喜
暗喜 2020-12-12 23:47

If I have a reference to Context, is it possible to finish the current activity?

I don\'t have the reference to current activity.

7条回答
  •  一整个雨季
    2020-12-12 23:50

    I know it's an old post but, perhaps it could be a good idea to call it this way:

    if(context instanceof Activity){
                    ((Activity)context).finish(); }
    

    This way we make sure we don't get any unnecesary ClassCastExceptions

提交回复
热议问题