Skip to content

Preferences not saved in Android Emulator (Linux) #6045

@akzincsystems

Description

@akzincsystems

Checklist

  • I have searched the issue tracker for open issues that relate to the same problem, before opening a new one.
  • This issue only relates to a single bug. I will open new issues for any other problems.

Describe the bug

When running my application in Android Emulator on Linux, preferences do not get saved.

They get saved running in web mode and as a Desktop application

Android Debug Bridge version 1.0.41
Version 35.0.0-11411520
Running on Linux 6.8.0-88-generic (x86_64)

Android Emulator V36.2.12-14214601

fyne cli version: v1.6.2
fyne library version: v2.7.1

How to reproduce

  1. Create application
  2. Uninstall previous version (Make command ${ADB} shell cmd package uninstall -k ${APP_ID})
  3. Build new version (Make command export ANDROID_NDK_HOME=${NDK_HOME} && fyne package -os android)
  4. Install new version to emulator (Make command ${ADB} install ${APP_NAME}.apk)
  5. Start app in emulator
  6. Go to settings screen, enter values and click on save button
  7. See confirmation dialog that settings have been saved
  8. Exit app and restart
  9. Go to settings screen. See that previously entered values have not been saved

Screenshots

No response

Example code

My code contains a Prefs struct (global params variable) which handles all operations for preferences. The prefs.Save() method is called in the OnSubmit callback for the settings screen.

// Save stores the configuration in the preference store
func (cfg *Prefs) Save() {
	p := fyne.CurrentApp().Preferences()
	p.SetString(awsKey, cfg.AwsAccessKey)
	p.SetString(awsSecret, cfg.AwsSecret)
	p.SetString(currentInstance, cfg.CurrenInstance)
	for i := 0; i < 10; i++ {
		slot := fmt.Sprintf("%s%d", "slot", i+1)
		p.SetString(fmt.Sprintf("ins%s", slot), cfg.Instances[slot])
		p.SetString(fmt.Sprintf("ids%s", slot), cfg.Ids[slot])
		p.SetString(fmt.Sprintf("reg%s", slot), cfg.Regions[slot])
	}
	cfg.Saved = true
}
        accessKey := binding.NewString()
	secretKey := binding.NewString()
	if err := accessKey.Set(params.AwsAccessKey); err != nil {
		panic(err)
	}
	if err := secretKey.Set(params.AwsSecret); err != nil {
		panic(err)
	}
	accessKeyItem := widget.NewFormItem("AWS Access Key", widget.NewEntryWithData(accessKey))
	secretKeyItem := widget.NewFormItem("AWS Secret Key", widget.NewEntryWithData(secretKey))

	form := &widget.Form{
		Items: []*widget.FormItem{
			accessKeyItem,
			secretKeyItem,
		},
		OnSubmit: func() {
	                params.Saved = false
			v, err := accessKey.Get()
			if err == nil {
				params.AwsAccessKey = v
			}
			v, err = secretKey.Get()
			if err == nil {
				params.AwsSecret = v
			}
			params.Save()
			dialog := dialog2.NewInformation("Success", "Settings saved", myWindow)
			dialog.Show()
		},
		OnCancel:    func() {},
		SubmitText:  "Save",
		CancelText:  "Cancel",
		Orientation: 0,
	}

Fyne version

2.7.1

Go compiler version

1.23.4

Operating system and version

Ubuntu 24.04.3 LTS

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    unverifiedA bug that has been reported but not verified

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions