Obecnie studiuję interfejs Bluetooth Android Bluetooth, a ja natknąłem się na przykład BluetoothChat. http://developer.android.com/resources/samples/BluetoothChat/index.htmlBluetoothChat zsynchronizowany onResume Metoda cyklu życia aktywności, dlaczego?
Zawiera wiele błędów, przede wszystkim prosty fakt, że używa interfejsu API 11, ale manifest nie wymusza tego minimalnego interfejsu API.
Inne Ciekawostką jest użycie zsynchronizowanego hasła na metodach cyklu życia działalności, jak na onResume:
@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();
}
}
}
Dlaczego ten parametr jest używany tam? Czy istnieje jakieś uzasadnione wytłumaczenie, czy po prostu ten, kto napisał kod, nie wiedział, że onResume będzie nazywane zawsze tą samą nitką? A może coś mi brakuje?
Z góry dziękuję!
Naprawdę chciałbym poznać odpowiedź na to pytanie, jak również ... –