Search code examples
androidandroid-workmanager

Android Worker does not extract value from inputData for some reason


Here is a screenshot of my debug view. It is clearly visible in variables view that intupData contains value for the key that corresponds KEY_ISSUE_ID (issue.id) but

inputData.getString(KEY_ISSUE_ID)

results in null. Even more strange is that in other Workers very same code works well. Is there any caveat that might lead to such behavior?

BTW. What differs this worker is that it is chained after bunch of other workers with ArrayCreatingInputMerger. According to the doc it should receive an output of these workers as an input. But it does not look like it receives these data.

the output of parent OneTimeWorkRequests are passed in as inputs to the children.


Solution

  • As per the ArrayCreatingInputMerger documentation:

    • If this is the first time we encountered the key:
      • If it's an array, put it in the output
      • If it's a primitive, turn it into a size 1 array and put it in the output

    So your inputData has an array of strings of size 1, not a String.

    Therefore you'd want to use getStringArray() and get the first element of that array (if you only care about the first element):

    val issueId = inputData.getStringArray(KEY_ISSUE_ID).firstOrNull()