Giter Club home page Giter Club logo

Comments (10)

gmk57 avatar gmk57 commented on September 12, 2024 1

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.

geecko86 avatar geecko86 commented on September 12, 2024 1

@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.

YoshihideSogawa avatar YoshihideSogawa commented on September 12, 2024 1

Please check on Ver 2.4.1

from floatingview.

YoshihideSogawa avatar YoshihideSogawa commented on September 12, 2024

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.

gmk57 avatar gmk57 commented on September 12, 2024

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.

YoshihideSogawa avatar YoshihideSogawa commented on September 12, 2024

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.

geecko86 avatar geecko86 commented on September 12, 2024

Thank you for the insights, @gmk57!

Have you guys found a workaround? @YoshihideSogawa

from floatingview.

gmk57 avatar gmk57 commented on September 12, 2024

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.

gmk57 avatar gmk57 commented on September 12, 2024

@YoshihideSogawa What do you think about implementing above-mentioned workaround?

from floatingview.

gmk57 avatar gmk57 commented on September 12, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.