Azure-Samples / Azure-Samples/ms-identity-android-kotlin

App crashes with "Don't keep activities" setting

Open
#23 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Kotlin
Stars
49
Forks
39
PR merge metrics
No merged PRs in 30d

Description

This sample assumes that it is run on a device with sufficient memory to make sure that the activity launching the authentication flow is still alive to receive the result via AuthenticationCallback. This assumption might not be true on low-memory devices.
Android's "Don't keep activities" allows to simulate a scenario where the Android system has killed the activity.
When running the app under this condition, it crashes:

```
java.lang.NullPointerException
at com.azuresamples.msalandroidkotlinapp.SingleAccountModeFragment.callGraphAPI(SingleAccountModeFragment.kt:307)
at com.azuresamples.msalandroidkotlinapp.SingleAccountModeFragment.access$callGraphAPI(SingleAccountModeFragment.kt:58)
at com.azuresamples.msalandroidkotlinapp.SingleAccountModeFragment$authInteractiveCallback$1.onSuccess(SingleAccountModeFragment.kt:279)
at com.microsoft.identity.client.PublicClientApplication.postAuthResult(PublicClientApplication.java:2351)
at com.microsoft.identity.client.SingleAccountPublicClientApplication$3.onTaskCompleted(SingleAccountPublicClientApplication.java:443)
at com.microsoft.identity.client.SingleAccountPublicClientApplication$3.onTaskCompleted(SingleAccountPublicClientApplication.java:434)
at com.microsoft.identity.common.java.controllers.CommandDispatcher.commandCallbackOnTaskCompleted(CommandDispatcher.java:650)
at com.microsoft.identity.common.java.controllers.CommandDispatcher.access$1000(CommandDispatcher.java:99)
at com.microsoft.identity.common.java.controllers.CommandDispatcher$4.run(CommandDispatcher.java:626)
at android.os.Handler.handleCallback(Handler.java:942)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7872)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in SingleAccountModeFragment.kt around callGraphAPI at line 307 and authInteractiveCallback at line 279. Reproduce the crash with Android's "Don't keep activities" setting, then verify the authentication result no longer causes a NullPointerException when the activity has been recreated.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, kotlin
Domain
authentication, mobile
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.