Finishing current activity from a fragment

前端 未结 11 1517
野的像风
野的像风 2020-12-13 02:02

I have a fragment in an activity that I am using as a navigation drawer. It contains buttons that when clicked start new activities (startActivity from a fragment simply ca

11条回答
  •  春和景丽
    2020-12-13 02:39

    When working with fragments, instead of using this or refering to the context, always use getActivity(). You should call

    getActivity().finish();
    

    to finish your activity from fragment.

提交回复
热议问题