我想通過活動之間的高分辨率drawable ints
和ImageViews
顯示,所以我在第一個活動Examples.class作出這一空白:如何在活動之間傳遞int數組?
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.
PLUS它doesn」 T在仿真器上工作。
你可以發佈日誌貓輸出嗎? – LokiSinclair
@LokiSinclair日誌沒有檢測到任何錯誤,因爲代碼在模擬器上正常工作。 – user2989698
@LokiSinclair我更新了日誌貓。 – user2989698