Tried to use permissions API while not attached to an Activity.
Issue Description
Tried to use permissions API while not attached to an Activity. I am using react-native-navigation to start a Tab Navigation. In one of the tabs I request permission to read Contacts. with this code:
getContacts = async () => {
const resp = await PermissionsAndroid.check(PermissionsAndroid.PERMISSIONS.READ_CONTACTS);
console.warn("Permission => " + resp);
if (resp) {
console.warn("GET ALL CONTACTS");
} else {
try {
const granted = await PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.READ_CONTACTS);
if (granted === PermissionsAndroid.RESULTS.GRANTED) {
console.warn("GET ALL CONTACTS");
} else {
console.warn("PERMISSION DENIED");
}
} catch (err) {
console.warn(err);
}
}
}
The permissions dialog is shown. But when I press allow or deny. The app crashes with this error
Tried to use permissions API while not attached to an Activity.
How can I handle this issue?
Steps to Reproduce / Code Snippets / Screenshots
Create a tab navigation and in the first tab request permission in the componentDidMount.
Environment
React Native Navigation version: 1.1.406 React Native version: 0.52.2 Platform(s) (iOS, Android, or both?): Android Device info (Simulator/Device? OS version? Debug/Release?): Simulator, device, any OS, any buildType.
I currently use a timeout of 500 ms. and everything works fine. But the crash happens from an Activity but yet it is not attached to an activity. makes no sense

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you believe the issue is still relevant, please test on the latest version and report back. Thank you for your contributions.
The issue has been closed for inactivity.
This is happening for me when requesting location permissions
I had to go into "App info" (Android emulator) and then concede Location permissions manually - but the app never asked for them. Now the app works... (in debug/dev still).
I am having the same issue with location permission. I am using react-native-navigation version 1, would that mean the issue is resolved in version 2?
Did you resolve it @garrottkai?
Any update???
facing same issue
Hi, Still, this issue is happening I notice that If I am putting the permission code on the componentDidMount() method then this is happenig. But it works with setTimeout() but I don't think it is the correct way. Looking for help.
componentDidMount() { this.requestLocationPermission(); }
I am using react-native-location library and this issue is happening to me because I am trying to request for location permission outside of the App.js (entry point of the App). I think, if you place permission requests in the useEffect or useLayoutEffect hooks the error will go away.