0

I am working on an application where the Splash Screen shows only an image. I have created a theme for my Splash Activity and the theme has a image as the background.

 <style name="SplashTheme" parent="AppTheme">
    <item name="android:windowBackground">@drawable/splash_screen</item>
</style>

Now sometimes I get OutOfMemoryException for some of the users in the Splash Screen. I am not able to reproduce the issue as it happens for specific devices only and I get to know about it through crashlytics logs only. I have been using different folders for different densities.

There are tons of questions on SO regarding this and all of them suggest not to use the image directly from the resources but instead scale down the image first and then load it in memory. Providing links to one of the questions

Link

Should we never set src to an ImageView or image background to an activity directly in XML? Because in that case we won't be able to scale down the image?

Community
  • 1
  • 1
thedarkpassenger
  • 7,158
  • 3
  • 37
  • 61
  • You commented on one of the answers stating the various file sizes of your image. This has absolutely *nothing* to do with the `OutOfMemoryException` you're getting crash logs for. Android decodes your image file into `Bitmap` data in memory, hence it's the number of pixels in your image that determines the memory requirements. All of this is already explained in the Q&A you link to, and so are ways to correctly handle this. – MH. Feb 19 '16 at 08:56

1 Answers1

1

NO you can set image in XML it is not bad practice as long as your image is small.

I think problem is your image resolution I have faced same issue.

my image size is in kb but resolution is very high around (1080x2048).

So I suggest you to check the size first then check resolution .

If you want to load that much of bigger image then you have to scale down

N J
  • 27,217
  • 13
  • 76
  • 96
  • 1
    My image for xhdpi folder is 29 kb and for xxhdpi folder is 44 kb. Guess on a very high resolution phone this can cause an error. – thedarkpassenger Feb 19 '16 at 08:51
  • as high resolution image android do some manipulation then for big resolution image (1080x248) is through out of memory. simply you can see info of image it will show you resolution – N J Feb 19 '16 at 08:52