Şu anda bluetooth Android API'sinde çalışıyorum ve BluetoothChat örneğine rastladım. http://developer.android.com/resources/samples/BluetoothChat/index.htmlBluetoothChat, Etkinlik Yaşam Döngüsü yaşam döngüsü yönteminde senkronize edildi, neden?
Bu, ilk başta API 11'i kullanan basit bir gerçektir, ancak bu minimum API'yi zorlama zorunluluğu yoktur.
Diğer ilginç şey onResume olduğu gibi, Etkinlik yaşam döngüsü yöntemleri senkronize anahtar kelimenin kullanılmasıdır:
@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();
}
}
}
bu anahtar kelimenin orada neden kullanılmıştır? Herhangi bir makul açıklama var mı, yoksa sadece kodu yazan kişi, onResume'nin her zaman aynı iş parçacığı tarafından çağrılacağını bilmiyor muydu? Ya da bir şey özlüyorum?
şimdiden teşekkür ederiz!
Bu sorunun cevabını gerçekten bilmek isterim. –