Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: refactor WalletActivity permission launcher to avoid InvalidStat… #1239

Merged
merged 1 commit into from
Dec 15, 2023

Conversation

HashEngineering
Copy link
Collaborator

@HashEngineering HashEngineering commented Dec 14, 2023

…eException

Issue being fixed or feature implemented

Fix:

Fatal Exception: java.lang.IllegalStateException
LifecycleOwner de.schildbach.wallet.ui.main.WalletActivity@1e0e6df is attempting to register while current state is RESUMED. LifecycleOwners must call register before they are STARTED.

androidx.activity.result.ActivityResultRegistry.register (ActivityResultRegistry.java:123)
androidx.activity.ComponentActivity.registerForActivityResult (ComponentActivity.java:842)
de.schildbach.wallet.ui.main.WalletActivityExt.getRequestPermissionLauncher (WalletActivityExt.kt:207)
de.schildbach.wallet.ui.main.WalletActivityExt.explainPushNotifications (WalletActivityExt.kt:224)
de.schildbach.wallet.ui.main.WalletActivity.onLockScreenDeactivated (WalletActivity.java:362) 

Related PR's and Dependencies

none

Screenshots / Videos

How Has This Been Tested?

  • QA (Mobile Team)

Checklist:

  • I have performed a self-review of my own code and added comments where necessary
  • I have added or updated relevant unit/integration/functional/e2e tests

Comment on lines -206 to -210
private val WalletActivity.requestPermissionLauncher: ActivityResultLauncher<String>
get() = registerForActivityResult(ActivityResultContracts.RequestPermission()) {
requestDisableBatteryOptimisation()
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This construct would create the ActivityResultLauncher when it is needed rather than when WalletActivity is initialized.

I think this code was generated by pasting Java code into a kotlin file.

Copy link
Member

@Syn-McJ Syn-McJ left a comment

Choose a reason for hiding this comment

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

Looks good

@HashEngineering HashEngineering merged commit 929ecab into master Dec 15, 2023
2 checks passed
@HashEngineering HashEngineering deleted the bugfix-permission-launcher-crash branch December 15, 2023 15:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants