Java 6类加载的速度有多快?(What's faster in Java 6 classloading?)
ProGuard主页列出了一项功能:
- 重新定位和预先验证Java 6的现有类文件,以充分利用Java 6的更快的类加载。
这是指Java 6中的区别是什么?
这很重要吗?
它是否对通过默认类加载器的同步方面的多线程造成的减速有影响?
The ProGuard home page lists as a feature:
- Retargeting and preverifying existing class files for Java 6, to take full advantage of Java 6's faster class loading.
What is the difference in Java 6 that this refers to?
Is it significant?
Does it have impact on slowdowns caused by multithreading through the synchronized aspects of the default classloader?
原文:https://stackoverflow.com/questions/10724942
最满意答案
PreferenceActivity
的文档说:如果您在旧模式下使用PreferenceActivity,则[PreferenceFragment]文档将在此处应用于已弃用的API。
PreferenceFragment的文档解释了正在发生的事情:
要检索此片段中的首选项层次结构将使用的SharedPreferences实例,请使用与此片段相同的包中的上下文调用getDefaultSharedPreferences(android.content.Context)。
这表明
PreferenceActivity#addPreferencesFromResource(...)
不会创建与原始名称相同的SharedPreferences
文件。 相反,它将文件合并到默认的共享首选项中。pref_general
文件不存在,当您尝试从中读取时,基本上就是创建它。 (虽然在编辑之前它实际上并不是在磁盘上创建的。)The docs for
PreferenceActivity
say:If you are using PreferenceActivity in its old mode, the documentation [for PreferenceFragment] applies to the deprecated APIs here.
And the docs for PreferenceFragment explain what's happening:
To retrieve an instance of SharedPreferences that the preference hierarchy in this fragment will use, call getDefaultSharedPreferences(android.content.Context) with a context in the same package as this fragment.
This suggests that
PreferenceActivity#addPreferencesFromResource(...)
does not create aSharedPreferences
file with the same name as the original. Instead, it merges the file into the default shared preferences. Thepref_general
file does not exist, and you're basically creating it when you attempt to read from it. (Though it's not actually created on disk until you edit it.)
相关问答
更多-
PreferenceActivity的文档说: 如果您在旧模式下使用PreferenceActivity,则[PreferenceFragment]文档将在此处应用于已弃用的API。 PreferenceFragment的文档解释了正在发生的事情: 要检索此片段中的首选项层次结构将使用的SharedPreferences实例,请使用与此片段相同的包中的上下文调用getDefaultSharedPreferences(android.content.Context)。 这表明PreferenceActivit ...
-
SharedPreferences userDetails = context.getSharedPreferences("userdetails", MODE_PRIVATE); Editor edit = userDetails.edit(); edit.clear(); edit.putString("username", txtUname.getText().toString().trim()); edit.putString("password", txtPass.getText().toStri ...
-
什么是PreferenceManager使用的上下文 获取内部存储的位置,以及IIRC,应用程序的包名称。 在不同背景下传递的重点是什么? 通常,任何Context都将为此方法调用执行。 原则上,您可以传入一些ContextWrapper来覆盖getDefaultSharedPreferences()将使用的内容。 what is context used for by PreferenceManager To get at the locations of internal storage and, II ...
-
如何自动展开PreferenceManager的所有节点(How to automatically expand all nodes of a PreferenceManager)[2023-11-24]
如果您创建PreferenceDialog的子类,则可以覆盖createTreeViewer方法并设置自动扩展级别: @Override protected TreeViewer createTreeViewer(final Composite parent) { TreeViewer viewer = super.createTreeViewer(parent); viewer.setAutoExpandLevel(AbstractTreeViewer.ALL_LEVELS); retur ... -
如果您从不在SharedPreferencesUtils调用init(...) ,则mContext始终为空 If you never call init(...) in SharedPreferencesUtils, mContext is always null
-
如果没有定义“出错”意味着什么,我就会猜测。 看看下面的代码片段: Editor e = PreferenceManager.getDefaultSharedPreferences(this).edit(); ((Intent) e).putExtra("sent", "activity_2"); e.commit(); 你正在为一个Intent投射Editor 。 这没什么意义,因为这两个类之间没有任何关系。 因此,您可能会在某处看到ClassCastException 。 相反,您应该摆脱强制转换并使 ...
-
改变这个: - SharedPreferences prefs = getSharedPreferences("My_Prefs", MODE_PRIVATE); 对此: - SharedPreferences prefs = v.getContext().getSharedPreferences("My_Prefs", MODE_PRIVATE); Change this :- SharedPreferences prefs = getSharedPreferences("My_Prefs", MOD ...
-
从logcat看来,你调用的方法是 PreferenceManager.getDefaultSharedPreferences(context); 如果此处的上下文为空,则可能存在此类异常。 所以尝试传递一个有效的上下文作为参数。 你可以使用下面的方法。 Context context = getApplicationContext(); From the logcat it seems that the method you called is PreferenceManager.getDefa ...
-
我最好的建议是在onResume生命周期方法中使用你的函数。 这样,只要您的应用程序成为焦点,它就会被调用。 它的工作原理如下: public void for123(View view){ SharedPreferences sharedPref = getSharedPreferences("userInfo",Context.MODE_PRIVATE); String name = sharedPref.getString("username", ""); numTxt.setText(n ...
-
看起来Context是null。 在addStringProperty(..)之前设置Context Prefs.init(getApplicationContext()); Prefs.addStringProperty("client_id", "1JDkv9sdfj8sf63rjs"); Looks like the Context is null. Set the Context before addStringProperty(..) Prefs.init(getApplicationConte ...