Where is a good place to call ViewModel method after Microsoft Graph successfully gets user info

Wei Wen 1,126 Reputation points
2022-05-12T20:48:31.63+00:00

I followed this link to create my Android app: https://learn.microsoft.com/en-us/graph/tutorials/android

In my app, I only used the SSO authentication methods from this tutorial to sign user in and then get user info. Once I got the user's info, I need to use that info to call ViewModel's method. But that caused crash. I think the reason is that the getting user method returns CompletableFuture. If it is Task, it should work. My intention was to call ViewModel's method inside the thenAccept closure of the CompletableFuture. If I cannot, I don't know any other way to get the user info into the ViewModel's method. The content of ViewModel's method is in viewModelScope.launch { }

The error I got is:
java.lang.IllegalStateException: Job StandaloneCoroutine is already complete or completing, but is being completed with CompletedExceptionally[java.lang.NoClassDefFoundError: kotlinx.coroutines.CoroutineExceptionHandlerImplKt]

Any help is greatly appreciated

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
12,504 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Wei Wen 1,126 Reputation points
    2022-05-13T18:49:39.417+00:00

    It turns out that I had a tiny typo in the url of the service which my ViewModel called its function to do remote fetch. Once it is fixed, there's no crash.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.