Sitelet https://github.com/GCX-HCI/grandcentrix-AndroidCodeStyle/issues/3
Skip to content
This repository was archived by the owner on Oct 27, 2025. It is now read-only.
This repository was archived by the owner on Oct 27, 2025. It is now read-only.

Keep Lifecycle methods together #3

Description

@passsy

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions