Finishing current activity from a fragment

前端 未结 11 1493
野的像风
野的像风 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:21

    Well actually...

    I wouldn't have the Fragment try to finish the Activity. That places too much authority on the Fragment in my opinion. Instead, I would use the guide here: http://developer.android.com/training/basics/fragments/communicating.html

    Have the Fragment define an interface which the Activity must implement. Make a call up to the Activity, then let the Activity decide what to do with the information. If the activity wishes to finish itself, then it can.

提交回复
热议问题