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

前端 未结 7 1657
暗喜
暗喜 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:54

    If you have access to the running view of the Activity you want to finish (for example, you are in a click listener), you could do:

    ((Activity)getContext()).finish();
    

    (With thanks to 2red13 to get me here).

提交回复
热议问题