Skip to content
This repository has been archived by the owner on Mar 16, 2021. It is now read-only.

Preferences class's onCreate is called more than once? #118

Open
zhutq opened this issue Sep 29, 2017 · 0 comments
Open

Preferences class's onCreate is called more than once? #118

zhutq opened this issue Sep 29, 2017 · 0 comments

Comments

@zhutq
Copy link

zhutq commented Sep 29, 2017

tray Version (E.g. 0.12.0)

0.12.0

How have you setup tray (E.g. Initialized in Application.onCreate, in an Activity, BroadcastReceiver, IntentService, MainThread)

Create new instance in Activity/Fragment/Service.

Device(s) (E.g. Samsung Galaxy S8)

Firefly-rk3288

Android Version (E.g. Marshmallow or better API 23)

Android 5.1.1, API 22

Description (Just a place with additional information, more == better)

I create a module and migrate preferences from SharedPreferences:

public class Preferences extends TrayPreferences {
    public Preferences(final Context context) {
        super(context, "MODULE_NAME", 1);
    }

    @Override
    protected void onCreate(int initialVersion) {
        super.onCreate(initialVersion);

        String[] keys = {
            // keys ..
        };
        SharedPreferencesImport[] imports = new SharedPreferencesImport[keys.length];
        for (int i = 0; i < keys.length; i++) {
            imports[i] = new SharedPreferencesImport(getContext(), "Settings", keys[i], keys[i]);
        }
        this.migrate(imports);
        Log.d("TAG", "Migrated from SharedPreference");
    }
}

Preferences is used in two Services (each has its own process) and several Activies. These Services and Activities each creates an instance of Preference in its onCreate method and use the instance.

I notice that "Migrated from SharedPreference" is logged more than once.
Am I all good? Thank you very much!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

1 participant