編輯:初級開發
Sometimes you have the need to set up some app-wide configuration information in an android app or need to create a class that can be used in multiple projects with a generic way of setting configuration values. This is particularly useful for things like API keys that will probably be different across aPPS but should be Accessible in the same way. There are several ways to do it, but the one I’ve come to prefer is adding a meta-data node to the androidManifest.XML file.
This fIEld can be used to store a boolean, float, int, or String and is later Accessed by the Bundle method for your data type (e.g., getInt()). Here is an example of how to define a value in your androidManifest.XML:
Reading this meta-data takes just a few lines of Java:
Activity extends ContextWrapper which has a getPackageManager() method. That method returns the PackageManager, which is used to fetch the ApplicationInfo, passing the package name and the meta-data flag. The returned ApplicationInfo contains a fIEld, metaData, which is actually a Bundle containing all the meta data. Line 4 fetches a String that is the same as the “android:name” parameter in the XML.
That sounds more complicated than it really is. Basically, if you have an Activity, you can fetch the Bundle that has all your meta-data from the androidManifest and use it throughout the app.
很多初入Android的開發者可能會發現經常遇到Force Close或ANR這樣的問題,一般我們通過android系統的錯誤日志打印工具Logcat可以看到出錯的內容
File 讀寫[功能]因為文件讀寫很平常 使用打算把這個功能寫出輔助類的形式 以便以後方便使用 就是:FileIOHelper[代碼]1. 定義指定的File 以及其上
HTC Hero作為一款硬件配置強悍的智能手機,對不同版本的android系統兼容性非常好,曾有用戶將HTC新機Espresso內的2.1版android系統和最新的S
在android開發中ListView是比較常用的組件,它以列表的形式展示具體內容,並且能夠根據數據的長度自適應顯示。抽空把對ListVIEw的使用做了整理,並寫了個小