- 浏览: 150372 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
louisliao:
你好请问你有遇到 repo upload 每次都要求输入用户名 ...
碰到的Git/Repo问题及其解决方法 -
viptmd:
谢谢 lz的解释。。受教了,正在搞dmc
开篇:Java Net & DLNA -
chxiaowu:
楼主,可不可以共享代码啊。 看代码才能理解啊
ActiveObject模式的一个java实现 -
aigyoo:
很有兴趣就是不知道怎么做
jUpload字符集设置 -
enlangs:
学习了。。
开篇:Java Net & DLNA
Firstly look at the code:
这是google I/O 2010演讲Writing zippy Android apps演示项目里的一段代码,作者Brad Fitzpatrick。
背景:
起先,Android的Editor只有commit一个提交方法:
后来呢,应该是在开发Gingerbread的时候,这帮googlers折腾了一堆优化性能的方法,然后就出来一个appy接口:
看完这两个方法的说明,你大概就明白了是神马意思了吧。反正是apply在某种程度上降低了main thread的负担,但还能保证数据修改的很及时。(注意这部分:You don't need to worry about Android component lifecycles and their interaction with apply() writing to disk. The framework makes sure in-flight disk writes from)
因此,出现这个SharedPreferencesCompat来兼容一下这两个api(compat就是compatible的缩写呀)。
ps:嗯。gingerbread为虾米快呢,这下有点了解了吧。。
/** * Reflection utils to call SharedPreferences$Editor.apply when possible, * falling back to commit when apply isn't available. */ public class SharedPreferencesCompat { private static final Method sApplyMethod = findApplyMethod(); private static Method findApplyMethod() { try { Class cls = SharedPreferences.Editor.class; return cls.getMethod("apply"); } catch (NoSuchMethodException unused) { // fall through } return null; } public static void apply(SharedPreferences.Editor editor) { if (sApplyMethod != null) { try { sApplyMethod.invoke(editor); return; } catch (InvocationTargetException unused) { // fall through } catch (IllegalAccessException unused) { // fall through } } editor.commit(); } }
这是google I/O 2010演讲Writing zippy Android apps演示项目里的一段代码,作者Brad Fitzpatrick。
背景:
起先,Android的Editor只有commit一个提交方法:
/** * Commit your preferences changes back from this Editor to the * {@link SharedPreferences} object it is editing. This atomically * performs the requested modifications, replacing whatever is currently * in the SharedPreferences. * * <p>Note that when two editors are modifying preferences at the same * time, the last one to call commit wins. * * <p>If you don't care about the return value and you're * using this from your application's main thread, consider * using {@link #apply} instead. * * @return Returns true if the new values were successfully written * to persistent storage. */ boolean commit();
后来呢,应该是在开发Gingerbread的时候,这帮googlers折腾了一堆优化性能的方法,然后就出来一个appy接口:
/** * Commit your preferences changes back from this Editor to the * {@link SharedPreferences} object it is editing. This atomically * performs the requested modifications, replacing whatever is currently * in the SharedPreferences. * * <p>Note that when two editors are modifying preferences at the same * time, the last one to call apply wins. * * <p>Unlike {@link #commit}, which writes its preferences out * to persistent storage synchronously, {@link #apply} * commits its changes to the in-memory * {@link SharedPreferences} immediately but starts an * asynchronous commit to disk and you won't be notified of * any failures. If another editor on this * {@link SharedPreferences} does a regular {@link #commit} * while a {@link #apply} is still outstanding, the * {@link #commit} will block until all async commits are * completed as well as the commit itself. * * <p>As {@link SharedPreferences} instances are singletons within * a process, it's safe to replace any instance of {@link #commit} with * {@link #apply} if you were already ignoring the return value. * * <p>You don't need to worry about Android component * lifecycles and their interaction with <code>apply()</code> * writing to disk. The framework makes sure in-flight disk * writes from <code>apply()</code> complete before switching * states. * * <p class='note'>The SharedPreferences.Editor interface * isn't expected to be implemented directly. However, if you * previously did implement it and are now getting errors * about missing <code>apply()</code>, you can simply call * {@link #commit} from <code>apply()</code>. */ void apply();
看完这两个方法的说明,你大概就明白了是神马意思了吧。反正是apply在某种程度上降低了main thread的负担,但还能保证数据修改的很及时。(注意这部分:You don't need to worry about Android component lifecycles and their interaction with apply() writing to disk. The framework makes sure in-flight disk writes from)
因此,出现这个SharedPreferencesCompat来兼容一下这两个api(compat就是compatible的缩写呀)。
ps:嗯。gingerbread为虾米快呢,这下有点了解了吧。。
发表评论
-
Android客户端数据采集工具包设计
2012-03-06 23:19 7484最近在做一款采集Android应用数据的工具包,类似友盟、fl ... -
[Android游戏开发]基于libgdx的一个简单游戏demo
2012-01-10 14:33 5122最近在利用业余时间自学游戏开发,在看《Begining And ... -
Something about vm gc
2011-10-20 11:06 961It works something like this ... -
图像处理的Dither和Banding
2011-10-12 17:21 13145由于前面的文章涉及到了这两个概念,而我又对图像处理一窍不通,所 ... -
Roman Guy的Android Trick系列文章笔记(三)
2011-10-12 16:08 3318以下所涉及的所有文章都被墙了。。 1.Android ... -
Roman Guy的Android Trick系列文章笔记(二)
2011-10-10 17:43 17665.Speed up your Android UI ... -
Roman Guy的Android Trick系列文章笔记
2011-09-21 15:02 1758Roman Guy是Android Framework ... -
Android开发闲言碎语
2011-08-29 10:52 10761. Android,任何app的生命都是短暂的,所以开发ap ... -
Android开发中的一些经验总结
2011-05-11 10:55 5052计划用这篇文章把目前我在Android领域的一些看到的、用到的 ... -
Android Contacts知识学习
2011-05-10 16:17 0最近接受Contacts这一块的工作,在这里把看到的想到的一些 ... -
Multithreading For Performance
2011-03-17 16:48 0... However, a ListView-specifi ... -
Saving data safely
2011-03-16 22:45 1136我们知道,在Android平台中,保存数据有3种方式:loca ... -
一个代码复用实例
2011-03-14 09:43 1145大概看了一下这篇文章: 新浪微博布局学习——妙用TabHost ... -
New Gingerbread API: StrictMode阅读笔记
2011-03-09 17:14 1164原文:New Gingerbread API: StrictM ... -
Android Memory Leaks
2011-03-08 23:20 1922前一阵子,有一个bug是关于monkey测试到的memory ... -
AndroidUI学习
2011-02-23 22:43 1930没搞过swing,也没丰富经验的j2me ui,ios的ui也 ... -
Android消息处理框架:Looper,Handler,MessageQueue ...
2011-02-23 22:34 2925看过冷冰的Android核心分析第十一篇:Android GW ... -
Android Service Framework分析
2011-02-23 22:14 4567当我在为fetion client工作 ... -
新的开始
2010-11-01 15:54 839要去做android,很高兴。关注这个平台很久,现在终 ...
相关推荐
at java.lang.ClassLoader.loadClass(Unknown Source) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Unknown Source) at ...
faultString: java.lang.reflect.InvocationTargetException faultActor: faultNode: faultDetail: {http://xml.apache.org/axis/}stackTrace: AxisFault faultCode: {...
1) Error injecting constructor, java.lang.NoSuchMethodError: org.apache.maven.model.validation.DefaultModelValidator: method 'void ()' not found at org.jetbrains.idea.maven.server.embedder....
at java.lang.Thread.run(Unknown Source) Caused by: java.lang.NullPointerException at com.semaphore.jna.LibraryFinder.loadPath(LibraryFinder.java:64) at com.semaphore.jna.LibraryFinder.<clinit>...
df = spark.read.format(com.mongodb.spark.sql.DefaultSource).load() File /home/cisco/spark-2.2.0-bin-hadoop2.7/python/lib/pyspark.zip/pyspark/sql/readwriter.py, line 165, in load
at java.lang.ClassLoader.loadClass(Unknown Source) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Unknown Source) at ...
【标题】:Easy.JAVA.to.Source.Converte 是一个专门用于将已编译的Java字节码文件(.class)转换回源代码(.java)的工具。这个软件可以帮助开发者在丢失或忘记源代码的情况下,从已有的.class文件中恢复部分或全部...
Source Server : changgou Source Server Type : MySQL Source Server Version : 50726 Source Host : 192.168.159.134:3306 Source Schema : changgou_all Target Server Type : MySQL Target Server ...
at java.lang.reflect.Method.invoke(Unknown Source) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44) at org.junit.internal.runners.model.ReflectiveCallable.run...
org.bouncycastle.openssl.PEMException: problem parsing ENCRYPTED PRIVATE KEY: java.lang.SecurityException: JCE cannot authenticate the provider BC at org.bouncycastle.openssl.PEMReader$...
Tube ...Traducir esta página Top comments Newest first. mark kenneth santos 2 years ago. nice one brod sis :) viva viva magicfive longlive ,,,,, proud to be a dsffcs.....Tripoud ...Traducir esta página ...
Path source = Paths.get("source.txt"); Path target = Paths.get("target.txt"); // 创建文件 Files.createFile(source); // 检查文件是否存在 if (Files.exists(source)) { System.out.println("Source ...
at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.load...
org.exolab.javasource.JEnum org.exolab.javasource.JType org.exolab.castor.util.List org.exolab.javasource.Header org.exolab.javasource.JClass org.exolab.javasource.JField org.exolab.castor.types.Date ...
今天在windows7下安装qt-opensource-windows-x86-5.12.9报错: gdb.exe -系统错误 无法启动此程序,因为计算机中丢失api-ms-win-core-path-l1-1-0.dll。尝试重新安装该程序以解决此问题
javax.wsdl.WSDLException: WSDLException: faultCode=PARSER_ERROR: Problem parsing '- WSDL Document -'.: org.xml.sax.SAXParseException: The element type "p" must be terminated by the matching end-tag ...
openlayers 加载蓝黑色天地图颜色工具类,openlayers 加载蓝黑色底图。 使用介绍: 直接 import 然后使用 TileSourceColor.getSource (图层对象,类型) 即可。... source: TileSourceColor.getSource(layer, type) });
java原始生成器#platform.javasource ## Java源代码生成器 该库允许您以“功能”样式从Java代码生成Java源代码。 只需将代码创建为模型并将其打印到打印流中 示例:创建Web servlet源代码 String pname = "my...
javashop_source_2.1.3.part1.rar JAVASHOP源码(内带jar包) 由于只能上传小于20MB的文件,所以压缩成两个文件上传,只要把这两个压缩包都下载后,然后选中两个包一起解压即可。。 javashop_source_2.1.3.part2....
at java.lang.Class.privateGetDeclaredMethods(Unknown Source) at java.lang.Class.getMethod0(Unknown Source) at java.lang.Class.getMethod(Unknown Source) at sun.launcher.LauncherHelper.getMainMethod...