Skip to content

feat(android): optimize Ti.Preferences#14459

Merged
hansemannn merged 1 commit into
mainfrom
androidPreferences
Jun 7, 2026
Merged

feat(android): optimize Ti.Preferences#14459
hansemannn merged 1 commit into
mainfrom
androidPreferences

Conversation

@m1ga
Copy link
Copy Markdown
Contributor

@m1ga m1ga commented Jun 6, 2026

Optimizing the Ti.Preferences code a bit not to rely on try/catch.

getPreference(String key) Two issues here:

  • systemProperties.get(key) throws JSONException for every non-tiapp.xml key
  • preferences.getAll().get(key) loads the entire preference map into memory on every call, even when the key doesn't exist

Fix: Use has() instead of try/catch. Guard getAll() with contains().

Test code

Ti.App.Properties.setString('givenName', 'Paul');
console.log('The value of the givenName property is: ' + Ti.App.Properties.getString('givenName'));

Ti.App.Properties.setBool('boolValue', true);
console.log('boolValue', Ti.App.Properties.getBool('boolValue', false));

console.log('boolValueDefault1', Ti.App.Properties.getBool('boolValueDefault1', false));
console.log('boolValueDefault2', Ti.App.Properties.getBool('boolValueDefault2'));

// get all
var props = Ti.App.Properties.listProperties();
for (var i = 0, ilen = props.length; i < ilen; i++) {
	var value = Ti.App.Properties.getString(props[i]);
	console.log(props[i] + ' = ' + value);
}

Copy link
Copy Markdown
Collaborator

@hansemannn hansemannn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the current PR diff (TiProperties.java only). I do not see a blocking regression: system properties still take precedence, preference fallback remains for missing or mismatched typed values, and git diff --check is clean. I did not run the Android test suite.

@hansemannn hansemannn merged commit 5a978f7 into main Jun 7, 2026
7 checks passed
@hansemannn hansemannn deleted the androidPreferences branch June 7, 2026 13:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants