As discussed in How to return hashmap in an aidl file thread, I am returning "Map" and not generics map like "Map" or an implementation of Map like a Hashmap. When I check the bound service side output, I get the required key-values in the map, i.e. the map is populated correctly. But the same function at the service side, when called from the client side, returns an empty Map because I initialized my Map in service as:
Map myMap = new HashMap();
Please note that the client service contract is good as the service has other methods which returns boolean, and some of them are void. All of them are working correctly. The problem is just with this method which is returning a Map, and I suppose I am doing some syntactical mistake.
Below is my service side of implementation:
public Map getStatus() {
List<MyObject> MyList = new ArrayList<>();
if (myDaggerInjectedObject != null) {
MyList = myDaggerInjectedObject.getMyList();
}
Map myMap = new HashMap();
for (MyObject myObject : MyList) {
myMap.put(myObject.getScannableId(), myObject.getStatus().name());
}
return myMap;
}
Below is my client code which calls the above bound service method:
public Map getStatus() throws RemoteException {
try {
Map status = myService.getStatus();
// the status object is set to blank hashmap, it should have some data i.e key-value pair
return status;
} catch (RemoteException e) {
Log.e(TAG, "Service connection not available");
throw e;
}
}
Can somebody help pointing out the mistake here?
I did just two things and that resolved this fishy behaviour (Fishy because the same server-client code was working on my dummy client and server android apps but not working on my production client and server apps):
Although the first point is not at all logical to me still, but I wanted to jot down in this answer for people to comment, if it COULD be of any issue in this scenario.