GCX-HCI / tray

a SharedPreferences replacement for Android with multiprocess support
Apache License 2.0
2.29k stars 273 forks source link

ContentProviderStorage work in general context #75

Closed ATXadam closed 8 years ago

ATXadam commented 8 years ago

Try to get the application context, but fall back to the general context if null

codecov-io commented 8 years ago

Current coverage is 99.84% (diff: 0.00%)

Merging #75 into master will decrease coverage by 0.15%

@@           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   

Sunburst

Powered by Codecov. Last update a2fccdd...123d55b

StefMa commented 8 years ago

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 💭 ?

passsy commented 8 years ago

Will close this in one week when @ATXadam doesn't explain how this can happen.

ATXadam commented 8 years ago

When a context is created from createPackageContext it does not have an Application context, thus yielding a null.

passsy commented 8 years ago

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?

ATXadam commented 8 years ago

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)