Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In a nutshell, add the required API units to the uses clause - the key ones in your case are <code>AndroidApi.Jni.JavaTypes</code>, <code>AndroidApi.Jni.App</code>, and <code>AndroidApi.Jni.GraphicsContentViewText</code>, together with <code>FMX.Helpers.Android</code> for some glue code - and call it pretty much like you might in Java. Java classes are exposed as interface types with an initial J; in practice the Android API uses nested classes quite a lot, and since Delphi doesn't support nested interface types, these become ParentClassName_ChildClassName:</p> <pre><code>var Prefs: JSharedPreferences; Editor: JSharedPreferences_Editor; I: Integer; F: Single; S: string; begin Prefs := SharedActivity.getPreferences(TJActivity.JavaClass.MODE_PRIVATE); Editor := Prefs.edit; Editor.putInt(StringToJString('MyIntKey'), 999); Editor.putFloat(StringToJString('MyFloatKey'), 123.456); Editor.putString(StringToJString('MyStrKey'), StringToJString('This is a test')); Editor.apply; I := Prefs.getInt(StringToJString('MyIntKey'), 0); F := Prefs.getFloat(StringToJString('MyFloatKey'), 0); S := Prefs.getString(StringToJString('MyIntKey'), StringToJString('')); </code></pre> <p>That said, I've recently put out a simple <code>TCustomIniFile</code> descendant that wraps the <code>SharedPreferences</code> API - see here for info:</p> <p><a href="http://delphihaven.wordpress.com/2013/09/12/a-few-xe5-related-bits/" rel="noreferrer">http://delphihaven.wordpress.com/2013/09/12/a-few-xe5-related-bits/</a></p> <p>In mapping the API to <code>TCustomIniFile</code>, one small issue I found is the fact <code>SharedPreferences</code> keys are strongly typed, and there doesn't seem to be a way to find out in advance what type a given key has (keys in <code>TCustomIniFile</code>, in contrast, are weakly typed). Because of this, for reading, I use the <code>getAll</code> method to retreive all keys and values as a <code>Map</code>/<code>JMap</code> (Java dictionary object in other words) and read individual keys from there.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload