GCX-HCI / grandcentrix-AndroidCodeStyle

Android code style settings for Android Studio at grandcentrix

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Keep Lifecycle methods together

passsy opened this issue · comments

Our internal developer survey shows that our developers want to keep Android Lifecycle methods together (for Activities and Fragments), in the correct order and before all other methods. They should not be sorted alphabetically like all other methods. #6

survey

Why is this beneficial?

  • Activities and Fragments should not contain business logic instead those classes provide callbacks for the Android Framework. Those methods are called in special order. Having this order in code helps to know when things are ready to be called.
  • When sorting those methods alphabetical and mix them with all others, they can end up in wrong order (although it actually works most of the time) or mix with other methods which are completely unrelated.
  • Activity lifecycle methods are protected whereas Fragment ones are public. When grouping by visibility those from Activity end up after all public methods. Especially those should be moved right after the constructor.

Implemented: c5a13f5