I'm experiencing an issue with TokenCredentials.create() when my app is cold started without Internet connection, but regains Internet connection after some seconds. After my app regains Internet connection, and we retry to authenticate, TokenCredentials.create() will immediately fail with UnknownHostException, even though the device has Internet connection.
Please take a look into my test project on GitHub where there is also a video demonstrating the problem.
https://github.com/erlingfjelstad/esri-auth-to-map/tree/master
Hello @ErlDeveloper
Thanks for the repro code.
I tried to isolate the bug you mentioned with TokenCredential.create(), so I modified your MainActivity to only load the TokenCredential when a button is clicked and I am not able to reproduce your bug.
It seems that your bug might be somewhere else.
Here's my modified MainActivity
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val viewModel = MainViewModel()
setContent {
val coroutineScope = rememberCoroutineScope()
Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding ->
Button(modifier = Modifier.fillMaxWidth(),onClick = {
Log.d("ArcGIS-Main", "onCreate: $innerPadding")
coroutineScope.launch {
viewModel.authenticate()
}
}) {
Text("Authenticate")
}
val uiState by viewModel.mapFlow.collectAsState()
when (val state = uiState) {
is UiState.Error -> {
Toast.makeText(this, "Error", Toast.LENGTH_SHORT).show()
Log.d("ArcGIS-Main", "onCreate: Error ${state.text}")
Log.d("ArcGIS-Main", "onCreate: Error ${state.title}")
}
UiState.Loading -> {
Log.d("ArcGIS-Main", "onCreate: LOADING")
}
is UiState.Success -> {
Toast.makeText(this, "Success", Toast.LENGTH_SHORT).show()
Log.d("ArcGIS-Main", "onCreate: Success $uiState")
}
}
}
}
}
}
Here's the video with the code above:
Thanks for your attention on this issue @Erick_1
I've pushed your suggestion to another branch and you can check it out here: https://github.com/erlingfjelstad/esri-auth-to-map/tree/erick_1-suggestion
However, I still have a problem when cold starting the app with airplane mode enabled, then try to authenticate with TokenCredentials.create(), then disable airplane mode and retry to authenticate with TokenCredentials.create()
Since I don't have permission to add a video demonstrating my problem here in this forum, I've uploaded another video to the readme file in the branch you can find on the link above
Again, thanks for your attention
@Erick_1 did you manage to reproduce the issue with the cold starting the app without Internett connection?
We are able to reproduce the bug when initializing the app without internet. Our team is going to look at for a potential solution.
We will keep you updated when we fix the issue.
Thanks.