olgamiller / SSTVEncoder2

Send images via SSTV
Apache License 2.0
126 stars 15 forks source link

Labels get lost due to activity life cycle #2

Closed Pygmalion69 closed 4 years ago

Pygmalion69 commented 4 years ago

After entering a label it will not appear in the image on the main screen, on a Samsung Galaxy S7 running Android 8.0.0. The cause is that the main activity is recreated when the user returns from the edit text activity. The constructor of the crop view is called which creates a new (empty) instance of the label collection.

$ ./adb logcat -s MainActivity EditTextActivity CropView
04-10 13:50:51.198 21906 21906 D MainActivity: onCreate()
04-10 13:50:51.273 21906 21906 D CropView: CropView(), new LabelCollection()
04-10 13:51:03.304 21906 21906 D EditTextActivity: onCreate()
04-10 13:51:04.113 21906 21906 D MainActivity: onDestroy()
04-10 13:51:14.059 21906 21906 D EditTextActivity: done(), Label intent: test
04-10 13:51:14.150 21906 21906 D MainActivity: onCreate()
04-10 13:51:14.170 21906 21906 D CropView: CropView(), new LabelCollection()
04-10 13:51:14.742 21906 21906 D EditTextActivity: onDestroy()

It works fine on a Nexus 4 running Android 5.1.1, as the activity is not recreated on this device:

D/MainActivity(18149): onCreate()
D/CropView(18149): CropView(), new LabelCollection()
D/EditTextActivity(18149): onCreate()
D/EditTextActivity(18149): done(), Label intent: test
D/EditTextActivity(18149): onDestroy()

So a more robust approach would be needed for the data structures to survive life cycle changes.

olgamiller commented 4 years ago

Thank you for your detailed bug report.

Unfortunately, I couldn't reproduce the issue on an Android Emulator for Android 8.0.

Anyway, I replaced android.support with androidx libraries to support Android 10. It is working fine on an Android Emulator for Android 9 and Android 10. Hopefully, it will also solve the problem on your device.

Please find the beta release here: https://play.google.com/store/apps/details?id=om.sstvencoder