-2

What I want to do is passing DataModel array between Activity by Intent.

DataModel class has Bitmap object and FirebaseVisionLabel object. I found many sites to implement this.

Many people said that DataModel class should implements Serializable or Parceable interface to pass DataModel[] or ArrayList<DataModel>.

So I tried, but the real problem was FirebaseVisionLabel class cannot be serializable. Also, I cannot modify that class because it is firebase library.

How can I pass DataModel array by intent??

Point

  1. Want to pass array or arraylist of my own class by intent.
  2. that class has unserializable object and I cannot modify.
  3. how can I pass or deal with it?
Ümañg ßürmån
  • 8,143
  • 4
  • 21
  • 40
baeharam
  • 413
  • 1
  • 5
  • 18

4 Answers4

0

Use Parceable. It works perfect

public class Test implements Parcelable
{
    FirebaseVisionLabel firebaseVisionLabel;
    String testString;

    protected Test(Parcel in) {
        testString = in.readString();
    }

    public static final Creator<Test> CREATOR = new Creator<Test>() {
        @Override
        public Test createFromParcel(Parcel in) {
            return new Test(in);
        }

        @Override
        public Test[] newArray(int size) {
            return new Test[size];
        }
    };

    public FirebaseVisionLabel getFirebaseVisionLabel() {
        return firebaseVisionLabel;
    }

    public void setFirebaseVisionLabel(FirebaseVisionLabel firebaseVisionLabel) {
        this.firebaseVisionLabel = firebaseVisionLabel;
    }

    public String getTestString() {
        return testString;
    }

    public void setTestString(String testString) {
        this.testString = testString;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(testString);
    }
}

After that for passing data through intent

   Test test = new Test();
    test.setTestString("test");
    test.setFirebaseVisionLabel(yourObject);

    Intent intent = new Intent(this, BaseActivity.class);
    intent.putExtra("key", test);
    startActivity(intent);
Erselan Khan
  • 458
  • 4
  • 12
0

Use the below code to get ArrayList data without Serialized or Parcelable:

Consider,

Intent intent = new Intent(this, your_second_class.class);
intent.putStringArrayListExtra("<your_name_here>", your_list_here);
startActivity(intent);

Then in your second class use:

Intent i = getIntent();  
new_list = i.getStringArrayListExtra("<your_name_here>");

Hope it will work fine.

Ümañg ßürmån
  • 8,143
  • 4
  • 21
  • 40
  • `putStringArrayListExtra` is for `ArrayList`, my goal is to pass `ArrayList`... DataModel is my own class which has Object variable for firebasevisionlabel and bitmap – baeharam Aug 20 '18 at 08:28
0

You may use Application class, which can be used in all the screen, activities.

So store array in Application class and used anywhere in app.

Parth Suthar
  • 123
  • 4
0

FirebaseVisionLabel doesn't have too many properties. You will need to serialize Label / Confidence /... (anything you care) yourself by creating your own VisionLabelParcelable class.

So far, there are not enough use cases to make ML Kit return a Parcelable FirebaseVisionLabel. Most apps should extract the info they are interested in and pass around if they want.

Isabella Chen
  • 2,343
  • 11
  • 24