Javascript Android Studio内存不足错误ViewFlipper

Javascript Android Studio内存不足错误ViewFlipper,javascript,android,out-of-memory,Javascript,Android,Out Of Memory,首先,我想说的是,请不要将此标记为重复,因为此问题与大多数其他问题不同。我正在尝试创建一个类似的人工屏幕保护程序。我试图通过创建一个带有ViewFlipper的活动来实现这一点,将一些图片放入其中,然后设置flipInterval以使事情顺利进行。当我尝试运行此活动时,我得到一个OutOfMemory错误。大多数建议都是缩小图片的大小,但这是不可能的,因为我已经包含的图片是最小尺寸。它们的总文件大小也在20kb到70kb之间。我现在总共有六张图片,但是我为其他活动加载到应用程序中的图片越多,我在

首先,我想说的是,请不要将此标记为重复,因为此问题与大多数其他问题不同。我正在尝试创建一个类似的人工屏幕保护程序。我试图通过创建一个带有
ViewFlipper
的活动来实现这一点,将一些图片放入其中,然后设置
flipInterval
以使事情顺利进行。当我尝试运行此活动时,我得到一个
OutOfMemory
错误。大多数建议都是缩小图片的大小,但这是不可能的,因为我已经包含的图片是最小尺寸。它们的总文件大小也在20kb到70kb之间。我现在总共有六张图片,但是我为其他活动加载到应用程序中的图片越多,我在屏幕保护程序中能够播放的图片就越少。有没有办法增加图片的数量?可能在其他活动中调用“.finish()”?我显然不确定。有什么解决办法吗


谢谢大家

希望这可能有用

public class AnimateBackgroundActivity extends Activity{

protected int[] backgroundImages;
protected ImageView mainBackground;
protected boolean isRunning;

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    isRunning = true;
    backgroundImages = new int[6];
    backgroundImages[0] = R.drawable.background0;
    backgroundImages[1] = R.drawable.background1;
    backgroundImages[2] = R.drawable.background2;
    backgroundImages[3] = R.drawable.background3;
    backgroundImages[4] = R.drawable.background4;
    backgroundImages[5] = R.drawable.background5;
}

protected void animateBackground()
{
    Runnable animate = new Runnable() {

        public void run() {
            for (int i = 0; isRunning; i = (++i % backgroundImages.length)) {
                final int j = i;
                runOnUiThread(new Runnable() {
                    public void run() {
                        mainBackground.
                        setImageResource(
                                backgroundImages[j]);
                    }
                });

                try {
                    Thread.sleep(5000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }finally {

                }
            }
        }
    };

    Thread animBackgroundThread = new Thread(animate);
    animBackgroundThread.start();
}

@Override
protected void onResume() {
    isRunning = true;
    animateBackground();
    super.onResume();
}

@Override
protected void onDestroy() {
    isRunning = false;
    super.onDestroy();
}

@Override
protected void onPause() {
    isRunning = false;
    super.onPause();
}
}


public class InitScreen extends AnimateBackgroundActivity {


private void initImageLoader() {
    Context context = getApplicationContext();

    DisplayImageOptions options = new DisplayImageOptions.Builder().cacheInMemory().cacheOnDisc().build();

    ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context).memoryCacheExtraOptions(480, 800)
            // default
            // =
            // device
            // screen
            // dimensions
            .discCacheExtraOptions(480, 800, CompressFormat.JPEG, 100).memoryCache(new LruMemoryCache(4 * 1024 * 1024)).memoryCacheSize(4 * 1024 * 1024).discCacheSize(50 * 1024 * 1024).discCacheFileCount(1000).defaultDisplayImageOptions(options).build();

    ImageLoader.getInstance().init(config);

}

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);


    initImageLoader();

    setContentView(R.layout.inital);
    mainBackground = (ImageView) findViewById(R.id.init_screen_background);
    animateBackground();

}

请告诉我您在viewflipper中使用的图像尺寸相同(宽度和高度)?@ManishJain我所有的图像都是
1280p
x
720p
我似乎无法导入
DisplayImageOptions
ImageLoaderConfiguration
LruMemoryCache
ImageLoader