So I finally came with a solution and it looks like this:

But it is not as simple as that line.
For the List<ProductQuantity> productQuantities
, to be able to transform itself into a Parcelable Array[] (not an Array[], or an ArrayList, they are not the same) the Pojo (in this case ProductQuantity.class
) MUST implement a Parcelable. like this:

Once you implement it, just press alt + Enter to implement all necessary methods.
BUT, That's not all.
The problem with having implemented methods in a ROOM Pojo used for relationship Queries is that it will not compile, so what you need to do next is to use the @Ignore interface on top of every method created by the Parcelable implementation.
Finally you will notice that it still does not compile, and for some reason, even tho you are Ignoring the constructor required by the Parcelable, you MUST create an EMPTY constructor for ROOM to be able to compile (even if a constructor was not necessary before it being a Parcelable)
The code:
public class ProductQuantity implements Parcelable {
@Embedded
public Quantity mQuantity_;
@Relation(
parentColumn = "child_product_id",
entityColumn = "product_id"
)
public Product mProduct_;
public ProductQuantity() {
/*Empty constructor required by ROOM*/
}
@Ignore
protected ProductQuantity(Parcel in) {
}
@Ignore
public static final Creator<ProductQuantity> CREATOR = new Creator<ProductQuantity>() {
@Override
public ProductQuantity createFromParcel(Parcel in) {
return new ProductQuantity(in);
}
@Override
public ProductQuantity[] newArray(int size) {
return new ProductQuantity[size];
}
};
/*This methods don't need to be ignored for some reason*/
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel parcel, int i) {
}
}
The conversion plus navigation:
List<ProductQuantity> productQuantities = adapter.getCurrentList();
ProductQuantity[] productQuantitiesArray = productQuantities
.toArray(new ProductQuantity[adapter.getItemCount()]);
ProductsAndQuantitiesFragmentDirections.ActionProductsAndQuantitiesByQuoteFragmentToProductListFragment direction;
Log.d(TAG, "onClick: quoteId is: " + quoteId);
direction = ProductsAndQuantitiesFragmentDirections
.actionProductsAndQuantitiesByQuoteFragmentToProductListFragment(productQuantitiesArray).setQuote(quoteId);
Navigation.findNavController(view).navigate(direction);
And one final tip to take notice is how the .toArray()
method of the List class, DOES NOT include the rows or number of items of the List itself, that's why it is of upmost importance that you manually place the number of items in the code, in this case the adapter.getItemCount()
method was used, but if you are working directly with a List<>, just use the .size() method of the List. in this particular case would be productQuantities.size()
