1

I have a class which is in a Jar file, and it does not implement parcelable and I cannot edit the Jar file. I get the object as a response from the server and I need to pass it to the next activity using parcelable, This class also has other Class objects. How can I achieve this ?

Here is the code of the class :

//The class whose Arraylist I want to send to another activity. //This class is inside JAR

public class MacroConfig implements IConfig, IData {
    private MacroIdentifiers identifiers;
    private ArrayList<MacroRel> relation;
    private ExecutionMode executionMode;
    private ArrayList<RuleConfig> ruleConfig;
    private ArrayList<String> instruction;
    private ArrayList<String> _type_id;
    private String type;
    @JsonAdapter(JsonConverter.class)
    private ArrayList<Extension> extension;
    @JsonAdapter(JsonConverter.class)
    private Expansion expand;

    public MacroConfig() {
    }

I tried things mentioned on blogs and other Stackoverflow questions but didn't find any proper solution to it.

2
  • "I tried things mentioned on blogs and other Stackoverflow questions".... Such as....? If you mention what you tried, then it prevents your question from being flagged as a possible duplicate Commented Apr 6, 2017 at 12:34
  • 2
    And can you not convert it to a JSON String? Why do you need Parcelable? Commented Apr 6, 2017 at 12:35

1 Answer 1

3

May be u can try this alternate way, From sender Activity:

intent.putExtra("myObject",new Gson().toJson(listObject));

in oncreate of receiver activity

List<MyObject> obj = new Gson().fromJson(getIntent().getExtras().getString("myObject"), new TypeToken<List<MyObject>>(){}.getType());
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the solution, but I need to pass an ArrayList of object not just an object.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.