Skip to content

Invert condition for lifecycle method calls#6401

Open
alesimula wants to merge 1 commit into
LawnchairLauncher:16-devfrom
alesimula:patch-1
Open

Invert condition for lifecycle method calls#6401
alesimula wants to merge 1 commit into
LawnchairLauncher:16-devfrom
alesimula:patch-1

Conversation

@alesimula

@alesimula alesimula commented Feb 16, 2026

Copy link
Copy Markdown

Shouldn't mLifecycleHelper be called manually on versions OLDER than Q?

Description

Fixes #(issue)

Reasoning

Testing

Type of change

Bug fix (A non-breaking change that fixes an issue)
New feature (A non-breaking change that adds functionality)
Breaking change (A fix or feature that would cause existing functionality to not work as expected)
Refactor (A code change that neither fixes a bug nor adds a feature)
Performance (A code change that improves performance)
Style (Code style changes)
Docs (Changes to documentation)
Chore (Changes to the build process or other tooling)

Summary by CodeRabbit

  • Refactor
    • Improved internal lifecycle management logic to ensure correct behavior across different Android versions.

Shouldn't mLifecycleHelper be called manually on versions OLDER than Q?
@validcube validcube self-assigned this Mar 6, 2026
@validcube validcube removed their request for review March 19, 2026 19:49
@validcube validcube removed their assignment Mar 19, 2026
@yasanglass

Copy link
Copy Markdown
Member

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Mar 28, 2026

Copy link
Copy Markdown
Contributor
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@yasanglass yasanglass self-requested a review March 28, 2026 13:46
@coderabbitai

coderabbitai Bot commented Mar 28, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

The condition logic for lifecycle helper method invocations in BaseActivity has been inverted. Previously executing when Utilities.ATLEAST_Q was true, these calls now execute when it is false, affecting multiple lifecycle event handlers.

Changes

Cohort / File(s) Summary
Lifecycle Helper Dispatch Inversion
src/com/android/launcher3/BaseActivity.java
Conditional logic inverted for lifecycle helper method calls across onCreate, onStart, onResume, onStop, onPause, onDestroy, and onSaveInstanceState methods. Methods now execute when Utilities.ATLEAST_Q evaluates to false instead of true.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~40 minutes

Poem

🐰 A flip of the switch, oh what a twist!
The lifecycle dances when conditions are kissed,
No more true, but false takes the lead,
Android will bounce to a different creed! 🔄

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive The description is incomplete; it lacks detailed reasoning, testing steps, and proper issue reference beyond a template placeholder. Provide detailed reasoning for why the condition inversion is needed, reference the actual issue number, and include testing steps to verify the fix works correctly.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title directly matches the main change: inverting the condition for lifecycle method calls in BaseActivity.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
✨ Simplify code
  • Create PR with simplified code

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/com/android/launcher3/BaseActivity.java`:
- Around line 310-312: The lifecycle conditional using Utilities.ATLEAST_Q is
correct but verify and ensure each lifecycle method (onCreate, onStart,
onResume, onPause, onStop, onDestroy, onSaveInstanceState) in BaseActivity calls
mLifecycleHelper.<correspondingMethod>(this) only when Utilities.ATLEAST_Q is
false; confirm the helper is registered via registerActivityLifecycleCallbacks()
in BaseActivity and that LifecycleHelper (ActivityLifecycleCallbacksAdapter)
implements all lifecycle handlers so no duplicate calls occur on Q+ devices.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 937be04f-5d1c-4772-8ff5-860668d69667

📥 Commits

Reviewing files that changed from the base of the PR and between 83399c3 and 3562784.

📒 Files selected for processing (1)
  • src/com/android/launcher3/BaseActivity.java

Comment on lines +310 to 312
if (!Utilities.ATLEAST_Q) {
mLifecycleHelper.onActivityStopped(this);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Description: Verify LifecycleHelper implementation and ensure it handles all lifecycle callbacks

# Find and examine the LifecycleHelper class
fd -t f 'LifecycleHelper.java' --exec cat {}

# Check if there are any other usages of mLifecycleHelper that might need similar treatment
rg -n 'mLifecycleHelper\.' --type java

Repository: LawnchairLauncher/lawnchair

Length of output: 825


🏁 Script executed:

# Search for LifecycleHelper class definition more broadly
rg -n 'class LifecycleHelper' --type java -A 5

Repository: LawnchairLauncher/lawnchair

Length of output: 53


🏁 Script executed:

# Also search for LifecycleHelper in import statements and other files
rg -n 'LifecycleHelper' --type java | head -20

Repository: LawnchairLauncher/lawnchair

Length of output: 1290


🏁 Script executed:

# Read the BaseActivity.java file around the lifecycle methods to see the full context
wc -l src/com/android/launcher3/BaseActivity.java

Repository: LawnchairLauncher/lawnchair

Length of output: 118


🏁 Script executed:

# Locate the actual LifecycleHelper.java file
fd -t f 'LifecycleHelper.java'

Repository: LawnchairLauncher/lawnchair

Length of output: 53


🏁 Script executed:

# Read the relevant sections of BaseActivity.java to verify the conditional pattern
sed -n '260,290p' src/com/android/launcher3/BaseActivity.java
sed -n '305,315p' src/com/android/launcher3/BaseActivity.java
sed -n '320,330p' src/com/android/launcher3/BaseActivity.java
sed -n '330,340p' src/com/android/launcher3/BaseActivity.java
sed -n '345,355p' src/com/android/launcher3/BaseActivity.java

Repository: LawnchairLauncher/lawnchair

Length of output: 2336


🏁 Script executed:

# Read the LifecycleHelper class definition
fd -t f -p '*util*LifecycleHelper*' --exec cat {}

Repository: LawnchairLauncher/lawnchair

Length of output: 372


🏁 Script executed:

# Find LifecycleHelper class file
fd -i lifecyclehelper -t f

Repository: LawnchairLauncher/lawnchair

Length of output: 120


🏁 Script executed:

# Search for the LifecycleHelper class definition with its interface implementation
rg -n 'class LifecycleHelper' --type java -A 10

Repository: LawnchairLauncher/lawnchair

Length of output: 53


🏁 Script executed:

# Read the LifecycleHelper Kotlin file to verify it implements Application.ActivityLifecycleCallbacks
cat src/com/android/launcher3/util/LifecycleHelper.kt

Repository: LawnchairLauncher/lawnchair

Length of output: 2813


LGTM: Consistent pattern across all lifecycle methods.

The conditional pattern if (!Utilities.ATLEAST_Q) is correctly applied to all seven lifecycle methods: onCreate, onStart, onResume, onStop, onDestroy, onPause, and onSaveInstanceState. This ensures manual helper invocation on pre-Q devices and automatic dispatch via registered callback on Q+.

The LifecycleHelper class (in src/com/android/launcher3/util/LifecycleHelper.kt) implements ActivityLifecycleCallbacksAdapter and properly handles all lifecycle events, with the helper being registered via registerActivityLifecycleCallbacks() in BaseActivity.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/com/android/launcher3/BaseActivity.java` around lines 310 - 312, The
lifecycle conditional using Utilities.ATLEAST_Q is correct but verify and ensure
each lifecycle method (onCreate, onStart, onResume, onPause, onStop, onDestroy,
onSaveInstanceState) in BaseActivity calls
mLifecycleHelper.<correspondingMethod>(this) only when Utilities.ATLEAST_Q is
false; confirm the helper is registered via registerActivityLifecycleCallbacks()
in BaseActivity and that LifecycleHelper (ActivityLifecycleCallbacksAdapter)
implements all lifecycle handlers so no duplicate calls occur on Q+ devices.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants