不定期更新,無廢話開始:List<Integer>不是List<Number>的子類,但List<Integer>是Collection<Integer>的子類。
- 一個(gè)List<? extends Number>的對(duì)象引用可以被賦值任何以Number或其子類為泛型的List或其子類的對(duì)象實(shí)例引用,如下例
1 List<? extends Number> nums = new ArrayList<Integer>();
- 泛型方法可以顯示指定其返回結(jié)果的泛型類型,如下例
1 Arrays.<Object>asList(1, 1.2, "Hello");
2 Collections.<Number>copy(objs, ints);
- Get與Put原則:當(dāng)僅從結(jié)構(gòu)中取出值則使用extends通配符,當(dāng)僅向結(jié)構(gòu)中添加值則使用super通配符,當(dāng)對(duì)一個(gè)結(jié)構(gòu)即取出又添加值時(shí)不要使用任何通配符。
1 //Collections.copy方法即使用super又使用extends的例子
2 public static <T> void copy(List<? super T> dest, List<? extends T> src)
1 //另一個(gè)例子,對(duì)同一個(gè)結(jié)構(gòu)即取值又設(shè)值,不使用任何通配符
2 public static double sum(Collection<? extends Number> nums) {
3 double s = 0.0;
4 for (Number num : nums) s += num.doubleValue();
5 return s;
6 }
7
8 public static void count(Collection<? super Integer> ints, int n) {
9 for (int i = 0; i < n; i++) ints.add(i);
10 }
11
12 //注意這個(gè)方法參數(shù)的簽名,沒有使用任何通配符
13 public static double sumCount(Collection<Number> nums, int n) {
14 count(nums, n);
15 return sum(nums);
16 }
啟動(dòng)應(yīng)用
onCreate
onStart
onResume
按退出鍵
onPause
onStop
onDestory
按HOME鍵或當(dāng)前應(yīng)用被其他全屏應(yīng)用覆蓋時(shí)(如電話呼入)
onPause
onStop
按HOME鍵后,再次點(diǎn)擊應(yīng)用圖標(biāo)或長按HOME鍵點(diǎn)擊任務(wù)列表中的應(yīng)用圖標(biāo)或覆蓋當(dāng)前應(yīng)用的其他全屏應(yīng)用退出后
onRestart
onStart
onResume
被彈出對(duì)話框覆蓋時(shí)(如彈出短信提醒對(duì)話框)或屏幕關(guān)閉時(shí)
onPause
對(duì)話框關(guān)閉時(shí)或屏幕點(diǎn)亮?xí)r
onResume
橫豎屏切換時(shí)
onPause
onStop
onDestory
onCreate
onStart
onResume
ImageView中有setImageURI,但是傳遞一個(gè)URI.parse("http://www.google.com.hk/tools/dlpage/res/chrome/images/chrome-205_noshadow.png")這樣的URL路徑不能成功載入網(wǎng)絡(luò)上的圖片,最終還是需要借助java.net.URL,如下代碼所示:
1 URL picUrl = new URL("http://www.google.com.hk/tools/dlpage/res/chrome/images/chrome-205_noshadow.png");
2
3 Bitmap pngBM = BitmapFactory.decodeStream(picUrl.openStream());
4
5 imageView.setImageBitmap(pngBM);
很簡(jiǎn)單吧,哪位朋友如果有更簡(jiǎn)單的方法請(qǐng)通知我。
懶得再翻譯,這段應(yīng)該很好理解,直接將Dev Guide中復(fù)制過來。
The SharedPreferences
class provides a general framework that allows you to save and retrieve persistent key-value pairs of primitive data types. You can use SharedPreferences
to save any primitive data: booleans, floats, ints, longs, and strings. This data will persist across user sessions (even if your application is killed).
To get a SharedPreferences
object for your application, use one of two methods:
getSharedPreferences()
- Use this if you need multiple preferences files identified by name, which you specify with the first parameter.
getPreferences()
- Use this if you need only one preferences file for your Activity. Because this will be the only preferences file for your Activity, you don't supply a name.
To write values:
- Call
edit()
to get a SharedPreferences.Editor
.
- Add values with methods such as
putBoolean()
and putString()
.
- Commit the new values with
commit()
To read values, use SharedPreferences
methods such as getBoolean()
and getString()
.
Here is an example that saves a preference for silent keypress mode in a calculator:
1
public class Calc extends Activity
{
2
public static final String PREFS_NAME = "MyPrefsFile";
3
4
@Override
5
protected void onCreate(Bundle state)
{
6
super.onCreate(state);
7
. . .
8
9
// Restore preferences
10
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
11
boolean silent = settings.getBoolean("silentMode", false);
12
setSilent(silent);
13
}
14
15
@Override
16
protected void onStop()
{
17
super.onStop();
18
19
// We need an Editor object to make preference changes.
20
// All objects are from android.context.Context
21
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
22
SharedPreferences.Editor editor = settings.edit();
23
editor.putBoolean("silentMode", mSilentMode);
24
25
// Commit the edits!
26
editor.commit();
27
}
28
}
首先內(nèi)部存儲(chǔ)路徑為/data/data/youPackageName/,下面講解的各路徑都是基于你自己的應(yīng)用的內(nèi)部存儲(chǔ)路徑下。所有內(nèi)部存儲(chǔ)中保存的文件在用戶卸載應(yīng)用的時(shí)候會(huì)被刪除。
一、 files
1. Context.getFilesDir(),該方法返回/data/data/youPackageName/files的File對(duì)象。
2. Context.openFileInput()與Context.openFileOutput(),只能讀取和寫入files下的文件,返回的是FileInputStream和FileOutputStream對(duì)象。
3. Context.fileList(),返回files下所有的文件名,返回的是String[]對(duì)象。
4. Context.deleteFile(String),刪除files下指定名稱的文件。
二、cache
1. Context.getCacheDir(),該方法返回/data/data/youPackageName/cache的File對(duì)象。
三、custom dir
getDir(String name, int mode),返回/data/data/youPackageName/下的指定名稱的文件夾File對(duì)象,如果該文件夾不存在則用指定名稱創(chuàng)建一個(gè)新的文件夾。
在MYSQL中如果在建表的時(shí)候沒有指定Timestamp字段是否為NULL,則系統(tǒng)自動(dòng)添加默認(rèn)值,使用DEFAULT NULL也不好用,其實(shí)是可以使用NULL直接指定的,如下:
`CREATE_DATE` TIMESTAMP NULL