Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Server side</strong></p> <p>My PHP is rather rusty but I am pretty sure that if you simply echo your json parsed result, then that information is capturen in the JSONObject on your android:</p> <pre><code>echo json_encode($response); </code></pre> <p><strong>Cracking up the JSONObject</strong></p> <p>On your android you should then hopefully have every piece of information from the $result object available.</p> <p>To pull out that information do something like (unrelated example just to show the mechanics):</p> <pre><code> JSONObject jsonObject; // ... retreived earlier in the code try { if (jsonObject.getString("status").equals("OK")) { jsonObject = jsonObject.getJSONArray("results") .getJSONObject(0); jsonObject = jsonObject.getJSONObject("geometry"); jsonObject = jsonObject.getJSONObject("location"); String lat = jsonObject.getString("lat"); String lng = jsonObject.getString("lng"); position = new LatLng(Double.valueOf(lat), Double.valueOf(lng)); } } catch (JSONException e) { Log.e(TAG, e.getMessage(), e); } </code></pre> <p><strong>Suggestion regarding shared preferences</strong></p> <p>Example saving string in shared preferences and retrieve it again anywhere in your app.</p> <pre><code>public class PreferencesData { public static void saveString(Context context, String key, String value) { SharedPreferences sharedPrefs = PreferenceManager .getDefaultSharedPreferences(context); sharedPrefs.edit().putString(key, value).commit(); } public static String getString(Context context, String key, String defaultValue) { SharedPreferences sharedPrefs = PreferenceManager .getDefaultSharedPreferences(context); return sharedPrefs.getString(key, defaultValue); } } </code></pre> <p>Usage:</p> <pre><code>// save a note to the 'mynote' key PreferencesData.saveString(context, "mynote", "This is a test note"); // retrieve the 'This is a test note' String String note = PreferencesData.getString(context, "mynote", ""); </code></pre> <p><strong>Optional note:</strong></p> <p>I prefer to have as few hard coded strings as possible, so I have a /res/values/strings_prefkeys.xml file that I use to store preference keys. For the note example this file would contain:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;resources&gt; &lt;string name="key_note"&gt;key_note&lt;/string&gt; &lt;/resources&gt; </code></pre> <p>And the above save and retrieval would then become:</p> <pre><code>// save a note to the 'mynote' key PreferencesData.saveString(context, context.getString(R.string.key_note), "This is a test note"); // retrieve the 'This is a test note' String String note = PreferencesData.getString(context, context.getString(R.string.key_note), ""); </code></pre> <p>This is simply a matter of organisation and minimizing the risk of accidental duplicate keys that would yield some hard to track down bugs. </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. This table or related slice is empty.
    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