兩個 Activity 之間通過 Intent 傳遞賬號、密碼、圖片資源 ID,運行報錯「test11已停止運行」,Logcat 顯示 java.lang.OutOfMemoryError。
圖片資源過大導致內存溢出:
ImageButton 直接引用 @drawable/a1 等高分辨率圖片,解碼進內存佔用超過 Dalvik/ART 堆限制(通常 16-256MB)。
BitmapFactory.Options.inSampleSize 采樣加載Glide.with(this).load(R.drawable.a1).into(imageButton);android:largeHeap="true" 在 Manifest pictureId 定義為 int 而非 Drawabletextview1 重複賦值導致 textview2/3 為 null,修正:textview1 = findViewById(R.id.t20);
textview2 = findViewById(R.id.t21);
textview3 = findViewById(R.id.t22);intent.getIntExtra("圖片id", 0) 默認值防崩潰Android 內存管理鐵律:大圖必須采樣加載,Intent 只傳標識符不傳對象,引入成熟圖片庫是專業標配。