0

I'm making an app that makes a web request with volley to an API once a day with work manager in kotlin.
Now, I want to change a text view in the main activity to the result of that request.
I couldn't change the text view from the worker class so I came up with this idea: to pass some values from the worker class back to the main activity using this.

The problem is that the workmanager returns the values before the web request is finished, so it's actually passing null.

val jsonArrayRequest = JsonArrayRequest(
    Request.Method.GET, url, null,
    { response ->
        val day = "it works!"
        val output: Data = workDataOf(applicationContext.getString(R.string.result_name) to day)
        result = Result.success(output)
    },
    { response ->
        result = Result.failure()
    }
queue.add(jsonArrayRequest)
return result

I know that if I need to put the return inside the first pair of curely brackets, but when I do it, android studio gives me an error...
So how can I fix this problem, or is there any other way I change the text view?

neta cohen
  • 27
  • 7

0 Answers0