0

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?

Community
  • 1
  • 1
Bhavesh Agarwal
  • 603
  • 2
  • 6
  • 13
  • it should, if `MyList` is not empty, is it? tried to `Log.d` the size of `MyList`? – pskink Mar 26 '17 at 14:29
  • Verified that, MyList is not empty. And when called the service method directly from the service app side, correct populated map is getting returned, the problem comes only when called from the client app. – Bhavesh Agarwal Mar 26 '17 at 16:39
  • then for testing simply call `myMap.put("key", "value");` and try again – pskink Mar 26 '17 at 16:47
  • What types are returned by `myObject.getScannableId()` and `myObject.getStatus().name()`? – Vasiliy Mar 26 '17 at 17:50
  • @Vasiliy, String is returned by both of these. Also, as I mentioned, when method is called from the service side itself, the map is correctly populated with String key-values. – Bhavesh Agarwal Mar 27 '17 at 04:21
  • @pskink, Tried that but there is something fishy :( Same code works in my dummy client and service apps. But not with my production app, I am just hoping that it is either a build issue or a syntactical miss. Trying harder now. – Bhavesh Agarwal Mar 27 '17 at 04:23
  • @BhaveshAgarwal, then I'd suggest that you post all the relevant code. – Vasiliy Mar 27 '17 at 08:58
  • @Vasiliy, thanks for your comment. I am done with this issue, and posted the stuff which I did to resolve this in the answer section. Thanks again! – Bhavesh Agarwal Mar 28 '17 at 16:52

1 Answers1

0

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):

  1. Different AIDL files on server and client: I noticed that the AIDL file on client side was a superset of that on the server side (the interface at the client side had 3 methods whereas at the server side 2 methods)
  2. Cleaning all environments: Did a clean build before rebuilding all my AIDL, Client, Server modules/Components.

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.

Bhavesh Agarwal
  • 603
  • 2
  • 6
  • 13