Closed ATXadam closed 8 years ago
@@ master #75 diff @@
========================================
Files 22 22
Lines 655 655
Methods 0 0
Messages 0 0
Branches 96 97 +1
========================================
- Hits 655 654 -1
Misses 0 0
- Partials 0 1 +1
Powered by Codecov. Last update a2fccdd...123d55b
Duplicate from #76. Please close #76 @passsy :)
For what is it for @ATXadam ?
I've never got a null
when I try to get the ApplicationContext
.
Maybe it can't be happen that the ApplicationContext
is null.. Otherwise the App was killed. But how do you can store something if there isn't an App 💠?
Will close this in one week when @ATXadam doesn't explain how this can happen.
When a context is created from createPackageContext it does not have an Application context, thus yielding a null.
If your Context
, no matter how it got created, has no applicationContext
you can wrap it with a ContextWrapper
:
class WrappedPackageContext extends ContextWrapper {
WrappedPackageContext(Context packageContext) {
super(packageContext);
}
@Override
public Context getApplicationContext() {
return this;
}
}
Context createApplicationContext(Context packageContext) {
return new WrappedPackageContext(packageContext);
}
http://stackoverflow.com/a/34938480/669294
But I still don't get why exactly are you creating a context with createPackageContext
? Are you trying to read the tray module of a different application?
I'll give that a shot and see if it works in this instance; but yes I am getting the tray module of a different package; I cannot do this over IPC since I need it to block the thread until I get the tray settings back for logic (so callbacks are instantly out)
Try to get the application context, but fall back to the general context if null