All posts
May 23, 2023 in Android2 min
Eureka: Android support to quickly understand Activity and Fragment classes
Posted by
Ragunath Jawahar
Ragunath Jawahar
@ragunathjawahar

Reading just the source code to understand a class is inefficient. The sheer amount of information, implementation details, and non-linear nature of source code require an alternative representation to grasp effectively. The interactive edge bundling graph in Eureka is the most successful alternative representation of source code we've experimented with in the past few years.

If you look at the source code of an object-oriented class, it is fundamentally a graph representing state and behavior. And ultimately, we end up connecting them in such a way it solves a specific problem for us. Therefore, to gain a quick understanding, we need to focus on the fields, methods, and how they are related to one another. Eureka's goal is to surface and highlight this information while limiting the amount of information developers need in order to comprehend a class. It is essential to remember that Eureka is a complementary solution and not a replacement for reading source code. It works best when you combine the two.

Inspecting a class

Field and method groups
Field and method groups

Running Eureka on any class creates an interactive edge bundling graph with two groups—fields and methods. These groups are spatially separated, and the tool draws relationships between them. The direction of the dependency relationship is color-coded, using red for outgoing dependencies and blue for incoming dependencies.

Hovering over a class member (field or method) on the graph will highlight relationships between members and can help you,

  1. Gain insights about the class
  2. Ask interesting questions about the relationships between class members

These are two primary ways to quickly and incrementally build a mental model about the problem and the solution space the class addresses.

Field and method groups (annotated)
Field and method groups (annotated)

The diagram above has two groups and is annotated in blue to help you see the grouping.

Experimental Android Support

With Eureka, we're constantly experimenting and figuring out ways to help developers become productive when working with classes. As a next step, one of the experimentations revealed it helps to group fields and methods related to the Android framework, thereby bringing in more structure when studying a class.

Field, method, Android field, and Android method groups (annotated)
Field, method, Android field, and Android method groups (annotated)

With experimental support for the Android framework, Eureka can now groups class members into 4 categories:

  1. Fields
  2. Methods
  3. Android Fields
  4. Android Methods

This grouping can now help you see how framework methods and APIs relate to your domain.

The framework grouping unlocks the following use cases:

  1. Quickly understand how lifecycle methods interact with your business logic.
  2. What framework APIs are your domain logic dependent upon?
  3. What framework dependencies should you break to get a function under test?

Activity and Fragment classes are not the only ones supported by this feature. You can find the list of all supported classes here. Please let us know if you need support for additional classes by raising a GitHub issue.

How to try it?

If you don't have Eureka installed, install it via Homebrew using the following command.

brew install legacycodehq/tap/eureka

To try the new experimental Android support, use the following Eureka command.

eureka watch -x android PassphrasePromptActivity

You will see an Android icon in the top bar when running in the experimental Android mode. Try it out on one of your Activity or Fragment classes, and let us know what you think! We're sure you'll have an eureka moment or more!

Overall, how helpful was this article?
😭🙁🙂😍

Stay ahead of the curve! 🚀

Subscribe now and never miss our cutting-edge, innovative content.
Address
Legacy Code Headquarters (OPC) Private Limited,
L-148, 5th Main Road,
Sector 6, HSR Layout,
Bengaluru, Karnataka-560102,
India.
© 2023–2024 Legacy Code HQ. All rights reserved.