Reputation: 193
I'm trying to call startActivityForResult()
and do the processing in the onActivityResult()
. I've also implemented onMapReady()
callback, which is initalizing variables and states of the activity and doing some processing. The problem is I can't access variable (getting nullpointerexception) which will be used for some processing in the onActivityResult()
, because the onActivityResult()
is called before the onMapReady()
finished (it's async). I want to know how to wait for the onMapReady()
finish before accessing onActivityResult()
.
I've looked into this solution, but I can't call onActivityResult()
manually.
How to pause at an Android lifecycle stage until callback is called?
Is there anyway I can hook the lifecycle events and start onActivityResult() after the onMapReady()?
Upvotes: 0
Views: 111
Reputation: 1023
why don't you use global variables?
see this for example:
var isMapReady = false
var onActivityResultCalled = false
fun doProcesses(){
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (isMapReady.not()) {
onActivityResultCalled = true
} else {
doProcesses()
onActivityResultCalled = false
}
}
@Override
public void onMapReady(GoogleMap googleMap) {
isMapReady = true
if (onActivityResultCalled) doProcesses()
}
Upvotes: 1