私は今、BluetoothのAndroid APIを勉強しています.BluetoothChatの例を調べました。 http://developer.android.com/resources/samples/BluetoothChat/index.htmlBluetoothChatはonResumeアクティビティのライフサイクルメソッドを同期しました。なぜですか?
これには多くのエラーが含まれています。まず、API 11を使用するという単純な事実がありますが、マニフェストはこの最小限のAPIを強制しません。
その他興味深いのは、onResume上のように、活動のライフサイクルメソッドにsynchronizedキーワードの使用である:
@Override
public synchronized void onResume() {
super.onResume();
if(D) Log.e(TAG, "+ ON RESUME +");
// Performing this check in onResume() covers the case in which BT was
// not enabled during onStart(), so we were paused to enable it...
// onResume() will be called when ACTION_REQUEST_ENABLE activity returns.
if (mChatService != null) {
// Only if the state is STATE_NONE, do we know that we haven't started already
if (mChatService.getState() == BluetoothChatService.STATE_NONE) {
// Start the Bluetooth chat services
mChatService.start();
}
}
}
このキーワードが使用されているのはなぜ?合理的な説明があるのでしょうか、コードを書いた人だけが、onResumeが常に同じスレッドによって呼び出されることを知らなかったでしょうか?それとも私は何かが恋しい?
ありがとうございます!
私は本当にこの質問への答えを知りたいです... –