What is the use case for a Fragment with no UI?

后端 未结 5 703
北荒
北荒 2020-12-05 22:48

The Android Developer guide has a decent section on the use of Fragments. One way to use Fragments is without a UI. There are a few references to using this as a means of

5条回答
  •  情书的邮戳
    2020-12-05 23:23

    I have a large chunk of fairly complex code that handles logins for various social networks - facebook, google, twitter. This is code that I need to re-use in different activities since the user can login from different places in the app. It doesn't belong in a base activity class because you can only inherit from one class and I'm using that inheritance for other, unrelated, functionality.

    A ui-less fragment is perfect for my situation and a fragment suits the need nicely since I need lifecycle callbacks, for example (facebook is notorious in this regard, needing, for example, onActivityResult, etc.).

提交回复
热议问题