Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReactContext#getCurrentActivity() is null in createViewInstance() #9310

Closed
foghina opened this issue Aug 9, 2016 · 7 comments
Closed

ReactContext#getCurrentActivity() is null in createViewInstance() #9310

foghina opened this issue Aug 9, 2016 · 7 comments
Assignees
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@foghina
Copy link
Contributor

foghina commented Aug 9, 2016

See discussion on #8661 for more info, we should never create views before we have an attached activity. This means we can either move the call to startApplication to onResume or set the current activity in onCreate.

@lschmierer
Copy link

ThemedReactContext#getCurrentActivity() seems to be allways null in react-native version 0.31.0. At least on property setting it is still null.

@nicolas-yaros
Copy link

Is there any updates? Still null for me

ghost pushed a commit that referenced this issue Aug 11, 2016
…ntext

Summary:
`ThemedReactContext` wraps the actual `ReactContext` but doesn't actually receive any lifecycle events, which would set `mCurrentActivity`, so that's always stuck as `null`. To fix, we override `has/getCurrentActivity` and forward the call to the wrapped context, which actually has the correct lifecycle status.

Fixes issue #9310 on github.

Reviewed By: mkonicek

Differential Revision: D3703005

fbshipit-source-id: 363e87ac91d50516899b413e823d5312cbb807f4
@foghina
Copy link
Contributor Author

foghina commented Aug 11, 2016

Fixed in 96e4121.

@foghina foghina closed this as completed Aug 11, 2016
@lschmierer
Copy link

Is this going to be released in 0.32 or only in 0.33-rc?

@foghina
Copy link
Contributor Author

foghina commented Aug 11, 2016

It will probably be in the next RC.

cmcewen pushed a commit to cmcewen/react-native that referenced this issue Aug 15, 2016
…ntext

Summary:
`ThemedReactContext` wraps the actual `ReactContext` but doesn't actually receive any lifecycle events, which would set `mCurrentActivity`, so that's always stuck as `null`. To fix, we override `has/getCurrentActivity` and forward the call to the wrapped context, which actually has the correct lifecycle status.

Fixes issue facebook#9310 on github.

Reviewed By: mkonicek

Differential Revision: D3703005

fbshipit-source-id: 363e87ac91d50516899b413e823d5312cbb807f4
mpretty-cyro pushed a commit to HomePass/react-native that referenced this issue Aug 25, 2016
…ntext

Summary:
`ThemedReactContext` wraps the actual `ReactContext` but doesn't actually receive any lifecycle events, which would set `mCurrentActivity`, so that's always stuck as `null`. To fix, we override `has/getCurrentActivity` and forward the call to the wrapped context, which actually has the correct lifecycle status.

Fixes issue facebook#9310 on github.

Reviewed By: mkonicek

Differential Revision: D3703005

fbshipit-source-id: 363e87ac91d50516899b413e823d5312cbb807f4
@cornedor
Copy link
Contributor

Do I have to wait for 0.33 or is there another way to get an Activity in a view?

@cosmith
Copy link
Contributor

cosmith commented Sep 8, 2016

Could this also cause a crash in PermissionsModule too for me in some cases?

Activity activity = getCurrentActivity();
if (activity == null) {
throw new IllegalStateException("Tried to use permissions API while not attached to an " +
"Activity.");

facebook-github-bot pushed a commit that referenced this issue Oct 12, 2016
Summary:
We're seeing a lot of crashes from `PermissionsModule` not being able to access the current activity, mentioned in #10009 and here: #9310 (comment)

As far as I can tell, there is no way to ensure the Activity exists since the `ReactContext` holds a `WeakReference` to the current Activity and it appears that the lifecycle calls are happening in the right order (so not the same as #9310).

This will at least allow people to catch the error in JS and update the UI or try again as opposed to crashing the app.

I'm working on some bigger changes in #10221 but this is a smaller change and important to get fixed I think.
Closes #10351

Differential Revision: D4010242

fbshipit-source-id: 7a76973bb2b3e45817d4283917740c89a10ec0b0
grabbou pushed a commit that referenced this issue Oct 25, 2016
Summary:
We're seeing a lot of crashes from `PermissionsModule` not being able to access the current activity, mentioned in #10009 and here: #9310 (comment)

As far as I can tell, there is no way to ensure the Activity exists since the `ReactContext` holds a `WeakReference` to the current Activity and it appears that the lifecycle calls are happening in the right order (so not the same as #9310).

This will at least allow people to catch the error in JS and update the UI or try again as opposed to crashing the app.

I'm working on some bigger changes in #10221 but this is a smaller change and important to get fixed I think.
Closes #10351

Differential Revision: D4010242

fbshipit-source-id: 7a76973bb2b3e45817d4283917740c89a10ec0b0
@facebook facebook locked as resolved and limited conversation to collaborators May 24, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

6 participants