Reputation: 83018
Looking into marshmallow permission modal, it calls onRequestPermissionsResult()
before onResume()
of Activity or Fragment.
If we have any action performed on Action result (i.e. permission allowed), like I want to remove current fragment, then it is not possible because fragment and container activity both are into pause state. So is there any way to call onResume()
before onRequestPermissionsResult()
?
I am using flags for permission, which is being reset on onRequestPermissionsResult()
and being verified on onResume()
. But this seems a confusing way in my case.
Upvotes: 3
Views: 1611
Reputation: 39846
There's no way to change the order implemented those callbacks but you can easily hack-around it. I'll show two different ways:
Simply post:
private static final Handler uiHandler = new Handler(Looper.getMainLooper());
@Override
public void onRequestPermissionsResult (int requestCode, String[] permissions, int[] grantResults) {
if(... condition ...)
uiHandler.post(onPermission_condition);
}
private Runnable onPermission_condition = new Runnable(){
@Override
public void run(){
... do stuff here
}
}
}
Use a flag:
private boolean shouldDoStuff = false;
@Override
public void onRequestPermissionsResult (int requestCode, String[] permissions, int[] grantResults) {
if(... condition ...)
shouldDoStuff = true;
}
@Override
public void onResume(){
super.onResume();
if(shouldDoStuff) {
shouldDoStuff = false;
... do stuff here
}
}
Upvotes: 4