I have an application that uses a service to create an ArrayList of custom objects (MyObject) every x seconds. Then I want my activity to get this ArrayList array.
Currently, I plan that the Service sends a message to the Activity handler every time it finishes a data request. I want the message to the handler to contain the ArrayList MyObjects.
When creating a method in Activity to get this ArrayList from a message, I noticed that I couldn’t.
If i tried
msg.getData().getParcelableArrayList("myObjects")
Then the method I passed it to the expected one so that the ArrayList would not accept it. If I tried to make the results:
(ArrayList<MyObject>)msg.getData().getParcelableArrayList("myObjects")
I got an error: Cannot cast from ArrayList<Parcelable> to ArrayList<MyObject>
MyObject implements Parcelable, and I successfully dispatched an ArrayList from my service to my activity when my activity calls a service method to get it. However, I am trying to get away from having my survey show my service for this data.
1) How can I send an ArrayList inside a package in a message to a handler?
2) Is there another model that I must use so that my service updates data in my activity that may or may not be visible? I always want the data in my activity to be the last of the Service.
source
share