0

I am using an animation in my splash screen. While the splash is shown the application does some preparations in the background like login.

The animation is created by using animation list as such:

<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
    android:oneshot="false">
    <item android:drawable="@drawable/part_00001" android:duration="35" />
    <item android:drawable="@drawable/part_00002" android:duration="35" />
    <item android:drawable="@drawable/part_00003" android:duration="35" />
    <item android:drawable="@drawable/part_00004" android:duration="35" />
    <item android:drawable="@drawable/part_00005" android:duration="35" />
    <item android:drawable="@drawable/part_00006" android:duration="35" />
    <item android:drawable="@drawable/part_00007" android:duration="35" />
    <item android:drawable="@drawable/part_00008" android:duration="35" />
    <item android:drawable="@drawable/part_00009" android:duration="35" />
    <item android:drawable="@drawable/part_00010" android:duration="35" />
    .
    .
    .
    <item android:drawable="@drawable/part_00069" android:duration="35" />
    <item android:drawable="@drawable/part_00070" android:duration="35" />

</animation-list>

This is my splash activity layout:

<RelativeLayout android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:background="#000">

    <ImageView
        android:id="@+id/logo_animation"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"/>

</RelativeLayout>

Then, to start the animation I do the following in onCreate method:

ImageView rocketImage;
AnimationDrawable rocketAnimation;
rocketImage = (ImageView) findViewById(R.id.logo_animation);
rocketImage.setBackgroundResource(R.drawable.movie);
rocketAnimation = (AnimationDrawable) rocketImage.getBackground();
rocketAnimation.start();

However, after I run the application 3-4 times it crashes and says:

java.lang.OutOfMemoryError: Failed to allocate a 4665612 byte allocation with 700512 free bytes and 684KB until OOM

What can I overcome this issue?

Keselme
  • 3,779
  • 7
  • 36
  • 68

2 Answers2

0

Where are your images placed in drawable or drawable-hdpi?

Ahmad Ayyaz
  • 774
  • 8
  • 25
  • They are placed in drawable. – Keselme Apr 03 '18 at 09:43
  • Just put them in drawable-hdpi and add Add hardwareAccelerated & largeHeap under application AndroidManifest.xml like this: `` And let me know if it works – Ahmad Ayyaz Apr 03 '18 at 09:49
  • @Keselme Put the images in drawable-nodpi folder. So that images are not being resized and forcing oom. Also optimize your images to reduce file size. There are lots of online tools for that. – Emre Aktürk Apr 03 '18 at 09:56
  • No problems. Always a pleasure. You can make it as an accepted answer so others can know as well. – Ahmad Ayyaz Apr 03 '18 at 10:05
0

Use this in manifest file :-

<application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:largeHeap="true"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">

</application>
Abhinav Gupta
  • 2,225
  • 1
  • 14
  • 30