Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android activity finished drawing

I'd like to take a screenshot as soon as the activity finishes drawing its layout. To take the screenshot I am using the rootView.setDrawingCacheEnabled(true); and getDrawingCache. My problem is that if the activity hasn't finished loading, that doesn't work.

I tried creating a thread that waits until getDrawingCache isn't null. But that's just aweful code, and crashes pretty often. Is there anyway to know when did an activity finish drawing its layout?

Thank you.

like image 358
David Ribeiro Avatar asked Sep 03 '26 01:09

David Ribeiro


1 Answers

Try overriding Activity's method :

public void onWindowFocusChanged(boolean hasFocus)

The activity should be finished drawing.

like image 50
IanH Avatar answered Sep 05 '26 16:09

IanH



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!