-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
After upgrade to Android embedding V2, still get Shared.activity is null / NullPointerException on android.content.Context.getResources() #390
Comments
It should be ok. If you try to create a new Fresh flutter app and you use the simple code example that you can find on the |
I'm facing the same issue, please any update or fix? |
There is no fix, it should already just work. Any example I run is just fine! |
@pichillilorenzo Thanks for the reply. This error occurred again today, so I've spent all morning trying to reproduce and identify the problem. Unfortunately, as I said in the original post, this only happens occasionally (maybe once every couple of days), which makes tracking down the problem very difficult. (Edit: it literally just happened again, immediately after I deployed the exact same app and it worked fine). The fact that it only happens occasionally makes me think there is some kind of timing issue or race condition going on. I'd be interested to hear if @addtek gets this error every time or only occasionally. For what it's worth, here's a link to a minimal example I've created with the exact configuration for android that I'm using in my app (manifest, build.gradle etc). So far I've been unable to reproduce the error using it :( I'll continue to watch out for this error and try to figure out the exact steps required to reproduce. Some more info:
|
I see that you don't call void main() {
// it should be the first line in main method
WidgetsFlutterBinding.ensureInitialized();
// rest of your app code
runApp(MyApp());
} Now it should work. Official wiki https://api.flutter.dev/flutter/widgets/WidgetsFlutterBinding/ensureInitialized.html |
Let me know if it works! If it does, then I will add this into my error message. |
@jamesncl i get the error everytime i run my app. |
Apologies, that line |
@addtek Aha! I am also using alarm manager to do background tasks (downloading the latest list of YouTube video IDs). I'm using the workmanager plugin, which uses Android's WorkManager under the hood. @addtek out of interest, when were you initialising Android WorkManager in your app? Do you do this before I'm going to remove the workmanager plugin and see if I get this error again. |
I initalise the Workmanager after in the main app view after a user is authenticated, so that's pretty way after 'runApp()'. actually i don't get the error right away when the app runs but when i try to play a video. |
Right, thanks to @addtek hint about AlarmManager, I now have a minimal reproducible example :) It seems to be a conflict with Android's AlarmManager. Here's how to reproduce:
Replace main.dart with this:
Amend
Build and run. It will immediately crash with this error:
If you comment out the Youtube controller and player, and replace with an empty Container, there is no crash. |
Yep I also only get the error when I have a youtube player widget on the screen. |
Thanks! I will try to debug it. I will let you know as soon as possible |
I found that there is a problem with the void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Workmanager.initialize(
callbackDispatcher,
isInDebugMode: true,
);
Future.delayed(const Duration(milliseconds: 3000), () {
Workmanager.registerOneOffTask("1", "simpleTask");
});
runApp(MyApp());
} |
Ok, I fixed it! I don't know why, but calling Because of this, a variable of mine gets This fix will be available in the next release |
Super cool thank you @pichillilorenzo |
Nice! Thanks @pichillilorenzo for responding so quickly. Looking forward to 3.4.0 :) |
Published new |
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug and a minimal reproduction of the issue. |
After upgrading to flutter embedding v2 I still get the following error occasionally:
Here is my Manifest.xml:
Here is my MainActivity (note I'm using the new embedding classes):
I'm also doing this in my flutter main.dart:
I've also done a
flutter clean
. I'm aware that this has been reported in earlier issues, and the solution was to upgrade to embedding V2 - but as far as I can tell I've done that - I've followed all the steps from here. What am I missing?Thanks
The text was updated successfully, but these errors were encountered: