简体   繁体   中英

calling parent activity method from fragment

I am little confuse which is the best way to call Parent Activity method as I can easily call parent Activity method from fragment using

1. ((Activity)getActivity()).getMethod()

and other way I have to create interface and doing onAttach stuffs etc. which also explained in android developer website link

now my question is which is the best way and why?

The best way is to create an interface. The reason is to make the fragment reusable ie It can be called by any activity of your application, who has implemented your fragment's interface.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM