retrobits / son_of_hunkypunk

Automatically exported from code.google.com/p/hunkypunk
22 stars 8 forks source link

Folder picking in Preferences is not properly loaded on app startup #40

Open BroadcastGames opened 7 years ago

BroadcastGames commented 7 years ago

On Android 7.0 Nexus 6. To reproduce the problem:

  1. Go into Preferences and change the folder to /sdcard/test123 instead of the default of "/sdcard/Interactive Fiction"
  2. completely close the app. Swipe it off the recent tasks so it is fully closed.
  3. Open the app, it will start to list games from the "/sdcard/Interactive Fiction" folder and not the one you picked
  4. Rotate the screen and now it will correctly choose the specified folder.

The problem is that the Activity onCreate does not read from SharedPreferences and uses the default folder name. Once you rotate the screen or go into Preferences and close Preferences it does read it.

The preferences are read in onResume, which is why rotating the screen causes the path to change. Here is a link to the relevant code: https://github.com/retrobits/son_of_hunkypunk/blob/master/app/src/main/java/org/andglkmod/hunkypunk/GamesList.java#L113

BroadcastGames commented 7 years ago

It's also notable that the dataDirectory() method in Paths.java seems to make assumptions about the file layout that experience shows are not always safe to make.

Paths.java line 34 in particular: https://github.com/retrobits/son_of_hunkypunk/blob/master/app/src/main/java/org/andglkmod/hunkypunk/Paths.java#L34

 File f = new File(cardDirectory(), "Android/data/org.andglkmod.hunkypunk")

This starts with "cardDirectory()" which is defined to be the external SD Card. On devices with a physical removable SD Card this can be a rather different layout than the expected. Then it goes further to assume a relative path to the data of the app. Methods like coverDirectory() build upon this path. The layout between Android 4.4, Android 5.0, and Android 6.0+ can all be rather different in the construction of the path. Then various OEM's like Samsung/Sony/LG can have their own unique arrangements.