facebook / fresco

An Android library for managing images and the memory they use.
https://frescolib.org/
MIT License
17.07k stars 3.75k forks source link

The right way of initialize Fresco(Not bug) #2379

Open thirtyyuan opened 5 years ago

thirtyyuan commented 5 years ago

Description

I called Fresco.init() in BaseApplication's onCreate() method, but my App initialize some necessary things on main thread synchronously, and asynchronously initialize some libs or unnecessary heavy things on other thread. Additionally, this crash always happened in background, seem like user didn't use it, so system killed it's main process, after that, user came back to my App.

I found initialize Fresco need 300ms, so, I determined to initialize Fresco asynchronously. But some Activity or Fragment need use Fresco immediately (such as SimpleDraweeView in xml), that's lead to I got the exception of「SimpleDraweeView was not initialized!」at sometimes (the rate of user crash is 0.13%).

Question

Thank you for any answer!

stale[bot] commented 5 years ago

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as "bug" or "enhancement" and I will leave it open. Thank you for your contributions.

thirtyyuan commented 5 years ago

That's my solution: I add a FrameLayout in onCreateView(), after async init finished, add the really layout which is I want to display.

teoking commented 4 years ago

@thirtyyuan Does your solution delay the showing up of first screen? Any measuring about this? I did some tests show that fresco initialization costs about 300ms to 700ms in cases. This would lead a delay for first screen even though moving to background (and my app has no splash screen).

thirtyyuan commented 4 years ago

Until now, my solution is no problem, it's just delay the process of addView(). Maybe you can try it, and if you have any idea, please let me know. ^_^