I have the follow code to get the screenshot
View screen = getWindow().getDecorView();
screen.setDrawingCacheEnabled(true);
screen.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH);
screen.buildDrawingCache();
Bitmap bitmap = screen.getDrawingCache();
The code is in onOptionsItemSelected in UI thread.
It runs fine when I test it manually. However, when I run the app with monkey, bitmap is nullI am not sure if it always null in monkey mode or just occasionally since monkey's randomness.
Any ideas that why monkey could behave differently? I do not want to blindly add a null pointer checker in later code.
Thanks
you should use buildDrawingCache(true) because buildDrawingCache() is same as buildDrawingCache(false).Make sure to copy bitmap to another one before using getDrawingCache() like below.
because its copy our bitmap before recycle() if you call setDrawingCacheEnabled(false).