Mobile Development 8 min read

Android Development Tips: Quick System Version Detection, Custom Button Spacing, Logcat Activity Tracking, and Gradle Configuration

This article presents several practical Android development techniques, including using stack traces to differentiate Android 10 and Android 12 versions, a unique method for setting button spacing via custom XML backgrounds, leveraging logcat to identify launched Activity classes, and configuring Gradle to share local installations for faster project setup.

Rare Earth Juejin Tech Community
Rare Earth Juejin Tech Community
Rare Earth Juejin Tech Community
Android Development Tips: Quick System Version Detection, Custom Button Spacing, Logcat Activity Tracking, and Gradle Configuration

Hello everyone, this article continues to share some common Android development tips that may help readers.

1. Quickly Locate System Version via Stack Trace

This section shares two tricks for rapidly identifying the current Android system version from a stack trace.

1. Distinguish Android 10‑ and Android 10+

Android 10 and above introduced the ActivityTaskManagerService , which took over some responsibilities of the former ActivityMangerService . Therefore, when the stack contains the term ActivityTaskManagerService , the device is running Android 10 or later. Devices running Android 9 or below do not have this class.

2. Distinguish Android 12‑ and Android 12+

This requires the Looper class. In Android 12+, the core message‑dispatch method loop() forwards to loopOnce() , which does not exist in earlier versions. Seeing loopOnce() in a stack trace indicates the device is Android 12 or newer.

2. A Quirky Way to Implement Button Spacing

Recently I encountered a project that achieved spacing between buttons—and between a button and the screen edges—using a method I hadn't seen before, so I share it here.

We start with a TextView that uses a custom XML background:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:height="70dp" android:gravity="center_vertical">
        <shape>
            <solid android:color="#ff0000" />
        </shape>
    </item>
</layer-list>

The key attributes are android:height and android:gravity , which define the background's height and vertical centering.

2.1 Adjust TextView Attributes

Set height to wrap_content so the final measured height is the maximum of the TextView's minHeight and the background's height.

Specify a minHeight larger than the background height to ensure spacing from the top of the screen.

Center the text vertically to avoid misalignment with the background.

After these adjustments, the visual result looks like this:

The empty space above and below the button is actually part of the TextView, so clicks on that area are also captured—a minor drawback but sometimes acceptable.

3. Logcat Quick View of the Current Activity Class

By filtering logcat with the keyword start u0 , you can see the Activity class that is being launched without modifying code or installing extra plugins.

Remember to set the logcat filter on the right side; otherwise you may need to switch to the system process view.

3.1 Example: Switching to Google Chrome

Logcat prints the package name and class name of the launched Activity.

3.2 Example: Switching to System Settings

The same start u0 filter works well for this case.

4. Point Project Gradle Configuration to a Shared Local Path

When working with multiple projects that use the same Gradle version, repeatedly downloading the distribution slows down development. Prepare the required Gradle versions locally and configure each project to point to the shared local directory.

This speeds up the first opening of a project and enables cache sharing across projects using the same Gradle version.

If a project is running fine and the network goes down, you may see errors about missing dependencies, but the local cache already contains them; simply enable offline mode to compile without network access.

Summary

This article introduced several useful Android development tricks, ranging from version detection via stack traces, a custom approach to button spacing, quick Activity inspection with logcat, to sharing Gradle installations for faster project setup. The author plans to explore Jetpack Compose in future posts.

developmentAndroidGradleLogcattipsButton SpacingVersion Detection
Rare Earth Juejin Tech Community
Written by

Rare Earth Juejin Tech Community

Juejin, a tech community that helps developers grow.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.