element-hq / element-hq/element-android
Open room from permalink does not work when app is in background
- Dominant language
- Kotlin
- Stars
- 3.7k
- Forks
- 917
- PR merge metrics
- No merged PRs in 30d
Description
### Steps to reproduce
1. Create and copy a permalink from a room timeline event
2. Optionally go back to return to Element home screen
3. Pass the app in background by taping on the phone home button
4. Paste and open the permalink in a browser
5. Open it with Element if requested
6. A BottomSheet dialog appears, displaying the room name with a button to open it
### What happened?
### What did you expect?
Click on the button should open the room and scroll to the related permalink event
### What happened?
Sometimes, nothing is happening, the bottom sheet is closed and we stay in the current screen
### My observation
By debugging the code and making some searches. I observed that the listener passed to the `MatrixToBottomSheet` class is null when I click on the button. I think that's due to the `WeakReference` that's hold the listener.
This [blog post](https://medium.com/android-news/android-weakreferences-how-not-to-5522bb325935) confirms my idea:
> the only objects that worth be keeping inside WeakReferences are objects that are kept by SDK somewhere:
Activities, Fragments, Views. Do not store local methods objects in WeakReferences.
To resolve it, I think we should remove the reference of the listener manually instead.
https://user-images.githubusercontent.com/11990514/133239018-3acfd2e6-1a38-4c5c-a95b-a715a3d511e0.mov
### Your phone model
Emulator Pixel 4, Samsung Galaxy A10s
### Operating system version
Android 11.0, 10.0
### Application version and app store
_No response_
### Homeserver
matrix.org
### Have you submitted a rageshake?
No
Contributor guide
Assessment
This issue has not been assessed yet.