1.练习的过程中熟悉Android Sample Code 的实例。学习参考实践的编程风格,熟悉android API。
(1)注释
(2)打印Log
if(D) Log.e(TAG, "create() failed", e);
if(D)Log.e(TAG, "- ON PAUSE-");
(3)synchronized method
mutithreading
(4)private final Handler mHandler = new Handler(){...}
final
(5)类的成员变量的命名 与 类中的类的成员变量的命名
private int mState; //类的成员变量的命名
private final BluetoothSocket mmSocket; //类中的类的成员变量的命名
(6)异常
try {
// This is a blocking call and will only return on a
// successful connection or an exception
mmSocket.connect();
} catch (IOException e) {
connectionFailed();
// Close the socket
try {
mmSocket.close();
} catch (IOException e2) {
Log.e(TAG, "unable to close() socket during connection failure", e2);
}
// Start the service over to restart listening mode
BluetoothChatService.this.start();
return;
}
2.全键盘编码,熟悉eclipse环境的快捷键,尽量少用鼠标。
(7)static关键字
不与对象关联,即使从未创建某个类的任何兑现,也可以调用static方法来访问static方法和static域。
public static class UpdateService extends Service
{ ... }
(8)数据交换格式JSONObject