我想在活动之间传递高分辨率的drawable ints,并将其显示在ImageViews上,因此在第一个活动示例中使其无效。类:

private void PATHS(int PATH_1, int PATH_2, int PATH_3, int PATH_4, int PATH_5)
{
    int[] xPATHS = {PATH_1,PATH_2, PATH_3, PATH_4, PATH_5};
    Intent intent = new Intent(Examples.this, ExamplesViewer.class);
    intent.putExtra("PATHS", xPATHS);
    startActivity(intent);

}

我在列表监听器中称之为:
    list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {

                PATHS(R.drawable.imageone, R.drawable.imagetwo, R.drawable.imagethree, R.drawable.imagefour, R.drawable.imagefive);
        }
    });
}}

然后我在第二个活动“examplesviewer.class”中收到它:
    Bundle intent = getIntent().getExtras();
    int[] PATHS = intent.getIntArray("PATHS");
    ImageView xImageView_1 = (ImageView) findViewById(R.id.PATH_1);
    ImageView xImageView_2 = (ImageView) findViewById(R.id.PATH_2);
    ImageView xImageView_3 = (ImageView) findViewById(R.id.PATH_3);
    ImageView xImageView_4 = (ImageView) findViewById(R.id.PATH_4);
    ImageView xImageView_5 = (ImageView) findViewById(R.id.PATH_5);


    final BitmapFactory.Options xbm = new BitmapFactory.Options();
    xbm.inSampleSize = 2;

    DisplayMetrics metrics = this.getResources().getDisplayMetrics();
    int width = metrics.widthPixels;
    int height = metrics.heightPixels;

    Bitmap xImage_1 = BitmapFactory.decodeResource(getResources(), PATHS[0], xbm);
    xImageView_1.setImageBitmap(xImage_1);
    xImageView_1.getLayoutParams().height = height;
    xImageView_1.getLayoutParams().width = width;
    Bitmap xImage_2 = BitmapFactory.decodeResource(getResources(), PATHS[1], xbm);
    xImageView_2.setImageBitmap(xImage_2);
    xImageView_2.getLayoutParams().height = height;
    xImageView_2.getLayoutParams().width = width;
    Bitmap xImage_3 = BitmapFactory.decodeResource(getResources(), PATHS[2], xbm);
    xImageView_3.setImageBitmap(xImage_3);
    xImageView_3.getLayoutParams().height = height;
    xImageView_3.getLayoutParams().width = width;
    Bitmap xImage_4 = BitmapFactory.decodeResource(getResources(), PATHS[3], xbm);
    xImageView_4.setImageBitmap(xImage_4);
    xImageView_4.getLayoutParams().height = height;
    xImageView_4.getLayoutParams().width = width;
    Bitmap xImage_5 = BitmapFactory.decodeResource(getResources(), PATHS[4], xbm);
    xImageView_5.setImageBitmap(xImage_5);
    xImageView_5.getLayoutParams().height = height;
    xImageView_5.getLayoutParams().width = width;

问题是,当我在模拟器上运行这个程序时,它运行得很好,但是当我在实际设备上运行它时,它会把我带到我的MainActivity
PS:我试着在几个设备上运行它,但仍然没有工作。
—————————————————————————————————————————————————
日志分类错误Out of memory on a 8294416-byte allocation.
而且它不再在模拟器上工作了。

最佳答案

而不是发送

int[] xPATHS = {PATH_1,PATH_2, PATH_3, PATH_4, PATH_5};
Intent intent = new Intent(Examples.this, ExamplesViewer.class);
intent.putExtra("PATHS", xPATHS);

尝试
int[] xPATHS = {PATH_1,PATH_2, PATH_3, PATH_4, PATH_5};
Intent intent = new Intent(Examples.this, ExamplesViewer.class);
Bundle bundle =new Bundle();
bundle.putIntArray("PATHS", xPATHS);                                 // Change here

而不是
Bundle intent = getIntent().getExtras();
int[] PATHS = intent.getIntArray("PATHS");

尝试
Bundle bundle = new Bundle();
int[] PATHS = bundle.getIntArrayExtra("PATHS");   // change here

09-09 21:53