Comments (10)
In real project showing/hiding of FloatingView is controlled by observing androidx.lifecycle.ProcessLifecycleOwner
inside Service. Sometimes user actions combined with other work in Android main thread results in lifecycle events delivered in quick succession. Specifically I suspect addViewToWindow()
and immediately removeAllViewToWindow()
produces abnormal state, so next call to addViewToWindow()
(even after some delay) crashes.
This happens rarely (~20 crashes per week among 300 users). I reproduced it after many minutes of repeated quick switching between our app and home screen. So the purpose of my demo project was not to avoid crash, but to reproduce crash reliably. ;)
from floatingview.
@gmk57 I applied the change you suggested and tested the sample project you created (in the OP).
Not the cleanest solution, but it certainly seems to have fixed the crashes! 🎉
It will have to do for now.
from floatingview.
Please check on Ver 2.4.1
from floatingview.
FloatingViewManager should be used within Service. It can not be used within Activity. For details, please read the README.
Also, FloatingView is not designed to work according to Activity's lifecycle. If you want to use PIP (Picture In Picture), please use another library.
from floatingview.
Of course, in real project we use it in Service, and exactly the same crash happens there. Test project does not bother with services for the sake of simplicity. And we show FloatingView when/if app in NOT visible, so PIP is not an option. Please reopen.
from floatingview.
I changed 'FloatingViewTest' to code that uses Service. It did not crash.
Also, when rewriting to this code, it did not crash.
handler.post(new Runnable() {
@Override
public void run() {
ImageView view = new ImageView(MainActivity.this);
view.setImageResource(R.mipmap.ic_launcher);
floatingViewManager.addViewToWindow(view, new FloatingViewManager.Options());
if (!isFinishing()) {
handler.postDelayed(this, 3000L);
}
}
});
handler.postDelayed(new Runnable() {
@Override
public void run() {
floatingViewManager.removeAllViewToWindow();
if (!isFinishing()) {
handler.postDelayed(this, 3000L);
}
}
}, 1000L);```
from floatingview.
Thank you for the insights, @gmk57!
Have you guys found a workaround? @YoshihideSogawa
from floatingview.
Given that v2.3.2 does not seem to have this issue, one possible solution is to replace checking for ViewCompat.isAttachedToWindow()
in FloatingViewManager.removeViewImmediate()
with simple try/catch. But this should be tested on device with Android 8 (where #89 is reproducible), and I don't have one at hand.
from floatingview.
@YoshihideSogawa What do you think about implementing above-mentioned workaround?
from floatingview.
Thank you very much! In test project v2.4.1 works fine, we'll try it in real life soon.
from floatingview.
Related Issues (20)
- get the removing view instead of coordinate
- Laggy floatingview HOT 8
- NullPointerException on mVelocityTracker
- Can't move view on some devices HOT 3
- getDisplayCutout() on a null object reference HOT 5
- old bug (#88) HOT 2
- Support Android Q HOT 3
- sample not work.
- NPE in addMovement HOT 1
- android x migration HOT 1
- Crash on display with oreo 8
- Support Android P HOT 5
- Caused by: android.view.WindowManager$BadTokenException: Unable to add window android.view.ViewRootImpl$W@990cb01 -- permission denied for window type 2038 HOT 2
- startObjectAnimation() only updates either X or Y
- Bugs on Galaxy S9+ HOT 7
- FloatingViewManager.removeAllViewToWindow() causes IllegalArgumentException HOT 1
- Floating view disappear in API level 26 HOT 1
- NullPointerException in onTouch, due to .getState() HOT 3
- Can't remove floating view HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from floatingview.