Created
May 15, 2017 19:00
-
-
Save luisfc/75e287311d117d1efa00288c96741739 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Iterate in Bundle | |
Bundle mBundle = data.getExtras(); | |
for (String key : mBundle.keySet()) { | |
Log.e(key, mBundle.get(key).toString()); | |
} | |
//Iterate in SharedPreferences | |
SharedPreferences myShPref = getSharedPreferences("mySharedPreferences", Context.MODE_PRIVATE); | |
#1 | |
Map<String, ?> allEntries = myShPref.getAll(); | |
for (Map.Entry<String, ?> entry : allEntries.entrySet()) { | |
Log.d("MAP values", entry.getKey() + ": " + entry.getValue().toString()); | |
} | |
#2 | |
Map<String, ?> map = myShPref.getAll(); | |
if (map.size() > 0) { | |
Set<String> playIds = map.keySet(); | |
} | |
implode(playIds) | |
public static String implode(Collection<String> data) { | |
Iterator<String> it = data.iterator(); | |
if (! it.hasNext()) | |
return ""; | |
StringBuilder sb = new StringBuilder(); | |
sb.append("(\""); | |
for (;;) { | |
String e = it.next(); | |
sb.append(e); | |
if (! it.hasNext()) | |
return sb.append("\")").toString(); | |
sb.append('"').append(',').append('"'); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment