0

Currently I have an ArrayList that I wanted to pass to another activity. I've already applied getParcelableArrayListbut it pass null to another activity. I've check the array for null, it's not. In the current activity before I pass it at least.

This is my code:

RecyclerViewOffline.java

Toast.makeText(context,"Clicked", Toast.LENGTH_SHORT).show();

Intent intent = new Intent(view.getContext(),OfflineActivity.class);

Log.d("Contexts Test : ", fileContents.get(holder.getLayoutPosition()).getTitle());

Bundle bundle = new Bundle();
//bundle.putParcelableArrayList("link",fileContents);
bundle.putParcelableArrayList("ArrayList",fileContents);
bundle.putInt("position",holder.getLayoutPosition());

intent.putExtra("bundle",bundle);
view.getContext().startActivity(intent);  

My receiving end:

OfflineActivity.java

 Bundle extras = getIntent().getBundleExtra("bundle");

 if(extras != null) {
   this.fileContents = extras.getParcelableArrayList("ArrayList");
   layoutPosition = extras.getInt("position");
   Log.d("Contexts Test Offline: ",""+ fileContents.get(layoutPosition).getTitle());
    }
 else{}
azriebakri
  • 1,131
  • 2
  • 11
  • 36

1 Answers1

1

As I can see

You didnt add the arraylist in the Parcelable in and out method and contructor.

This will solve your issue.

JAAD
  • 12,349
  • 7
  • 36
  • 57