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

前端 未结 7 1636
暗喜
暗喜 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-13 00:03

    In my Case following worked,

    I need to finish my activity in a AsyncTask onPostExcute().

    Where my AsyncTask class is separate public class , which has a constructor with param of Context.

    ((Activity)(mContext)).finish();
    

    Only the above worked for me... Anyway I got this idea from @2red13 and @lucy answers... Thanks to all...

提交回复
热议问题