create new menuInflater or getMenuInflater() from activity?

前端 未结 3 663
夕颜
夕颜 2021-01-02 08:59

I\'m creating new option menu inside fragment but after reading http://developer.android.com/resources/articles/avoiding-memory-leaks.html which said to it\'s better to use

3条回答
  •  耶瑟儿~
    2021-01-02 09:50

    You should use MenuInflater instance that is passed to the method public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) (notice the 2nd argument)
    There's no real difference, because normally you will "forget" it as soon as you finish using it, but why would you need to create one if you already have one from the arguments?

提交回复
热议问题