GCX-HCI / tray

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

Compiler complains passing TrayStorage.Type.USER #73

Closed jonameson closed 8 years ago

jonameson commented 8 years ago

The following causes the compiler to complain; TrayStorage.Type.USER needs to be an int.

private class MyPreference extends TrayPreferences {
    public MyPreference(@NonNull final Context context) {
        super(context, "myModule", VERSION, TrayStorage.Type.USER);
    }
}
jannisveerkamp commented 8 years ago

This is correct. The third Parameter has to be an int: The Version Code.

You didn't define it. Add

private static final int VERSION = 1;

to your class and you should be fine. You can also remove the last Parameter since its the standard behavior (TrayStorage.Type.USER).

jonameson commented 8 years ago

Hey, thanks for the quick reply. So the issue is not the VERSION param. I'm just saying that the constructors 4th param should be an enum of type "TrayStorage.Type". Or the "TrayStorage.Type" should be int and not enums. You guys should possible properly define that unless I'm not understanding something... :P

jannisveerkamp commented 8 years ago

I'm not sure if I understand you correctly. You can pass 4 Parameters into the Constructor:

  1. A context (Type: Context)
  2. The name of the module (Type: String)
  3. The version code (Type: int)
  4. (optional) A storage type (Type: TrayStorage.Type)

Your posted Code should work if you define VERSION as an int.

jonameson commented 8 years ago

Ah, you are correct. I was incorrectly using the constructor override. I was trying to pass the TrayStorage.Type as an int. My apologies. :/

jannisveerkamp commented 8 years ago

You're welcome 😄