I wanted to parse a VideoView object to json so that I could pass it to a different thread other than the Main Activity class using jobparameters.
My code looks like this:
VideoView videoViewN = findViewById(R.id.video);
Gson g = new Gson();
String json = g.toJson(videoViewN); //this is the line that causes the error
PersistableBundle bundle = new PersistableBundle();
bundle.putString("VideoView", json);
JobInfo info = new JobInfo.Builder(123, componentName)
.setPersisted(true)
.setExtras(bundle)
.setPeriodic(5 * 60 * 1000)
.build();
But it throws error like this:
2020-09-08 16:49:30.408 19352-19352/com.example.ses_adplatform_test E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.ses_adplatform_test, PID: 19352
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.ses_adplatform_test/com.example.ses_adplatform_test.MainActivity}: java.lang.IllegalArgumentException: class android.widget.MediaController declares multiple JSON fields named mContext
How do I fix this? Thank you!
PS: the reason why I need to parse it to json is that jobparameters do not accept datatypes other than string, int, etc. I used code from the following link as a reference for this solution. Android JobScheduling - I need to pass an object to my job but how?