ERROR:
2019-07-25 23:35:33.030 13258-13258/com.example.imagenes E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.imagenes, PID: 13258 java.lang.OutOfMemoryError: Failed to allocate a 1179136012 byte allocation with 4194304 free bytes and 350MB until OOM at dalvik.system.VMRuntime.newNonMovableArray(Native Method) at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method) at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:620) at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:455) at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:1155) at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:720) at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:571) at android.content.res.Resources.loadDrawable(Resources.java:858) at android.content.res.TypedArray.getDrawable(TypedArray.java:928) at android.widget.ImageView.(ImageView.java:162) at android.widget.ImageView.(ImageView.java:150) at android.support.v7.widget.AppCompatImageView.(AppCompatImageView.java:71) at android.support.v7.widget.AppCompatImageView.(AppCompatImageView.java:67) at android.support.v7.app.AppCompatViewInflater.createImageView(AppCompatViewInflater.java:181) at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:105) at android.support.v7.app.AppCompatDelegateImplV9.createView(AppCompatDelegateImplV9.java:1035) at android.support.v7.app.AppCompatDelegateImplV9.onCreateView(AppCompatDelegateImplV9.java:1092)
Fuera de memoria, he intentado poner mil soluciones como en Manifest
el android:largeHeap="true"
típico y otro que se suele comentar pero nada, si pongo iconos en vez de imágenes grandes sí que va, por lo que es el tamaño, ¿cómo puedo incorporar imágenes de 10 MB o más en mi App o tiene un límite y tengo que bajarlas a 5MB o cuánto?
Landscape.java:
public class Landscapes extends AppCompatActivity {
RecyclerView mRecyclerView;
int[] mPlaceList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_landscapes);
mRecyclerView = findViewById(R.id.recyclerview);
GridLayoutManager mGridLayoutManager = new GridLayoutManager(Landscapes.this, 2);
mRecyclerView.setLayoutManager(mGridLayoutManager);
mPlaceList = new int[]{R.drawable.calendar, R.drawable.coliseum, R.drawable.park,
R.drawable.salad};
MyAdapter myAdapter = new MyAdapter(Landscapes.this, mPlaceList);
mRecyclerView.setAdapter(myAdapter);
}
}
activity_landscape.xml:
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical" />
Adapter.java:
public class MyAdapter extends RecyclerView.Adapter<PlaceViewHolder> {
private Context mContext;
private int[] mPlaceList;
public MyAdapter(Context mContext, int[] mPlaceList) {
this.mContext = mContext;
this.mPlaceList = mPlaceList;
}
@Override
public PlaceViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.recyclerview_custom_layout,
parent, false);
return new PlaceViewHolder(view);
}
@Override
public void onBindViewHolder(final PlaceViewHolder holder, int position) {
holder.mPlace.setImageResource(mPlaceList[position]);
holder.mPlace.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent mIntent = new Intent(mContext, DetailActivity.class);
mIntent.putExtra("Image", mPlaceList[holder.getAdapterPosition()]);
mContext.startActivity(mIntent);
}
});
}
@Override
public int getItemCount() {
return mPlaceList.length;
}
}
class PlaceViewHolder extends RecyclerView.ViewHolder {
ImageView mPlace;
public PlaceViewHolder(View itemView) {
super(itemView);
mPlace = itemView.findViewById(R.id.ivPlace);
}
}
activity_Detail.xml:
unicamente tengo el imageView con id: imageView
Detail.activity.java:
public class DetailActivity extends AppCompatActivity {
ImageView mPlace;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_detail);
mPlace = findViewById(R.id.imageView);
Bundle mBundle = getIntent().getExtras();
if(mBundle != null){
mPlace.setImageResource(mBundle.getInt("Image"));
}
}
}
Actualizo error:
2019-07-26 18:07:59.533 16235-16235/com.example.imagenes E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.imagenes, PID: 16235 java.lang.OutOfMemoryError: Failed to allocate a 1179136012 byte allocation with 4194304 free bytes and 343MB until OOM at dalvik.system.VMRuntime.newNonMovableArray(Native Method) at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method) at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:620) at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:455) at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:1155) at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:720) at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:571) at android.content.res.Resources.getDrawable(Resources.java:771) at android.content.Context.getDrawable(Context.java:525) at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:358) at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:198) at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:186) at android.support.v7.content.res.AppCompatResources.getDrawable(AppCompatResources.java:100) at android.support.v7.widget.AppCompatImageHelper.setImageResource(AppCompatImageHelper.java:85) at android.support.v7.widget.AppCompatImageView.setImageResource(AppCompatImageView.java:93) at com.example.imagenes.DetailActivity.onCreate(DetailActivity.java:19) at android.app.Activity.performCreate(Activity.java:6679) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726) at android.app.ActivityThread.-wrap12(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6119) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)