Buggy code:
public class MetaWatchService extends Service { static volatile Context context ; public static BluetoothAdapter bluetoothAdapter ; BluetoothSocket bluetoothSocket ; static InputStream inputStream ; static OutputStream outputStream ; TelephonyManager telephonyManager ; AudioManager audioManager ; NotificationManager notificationManager ; RemoteViews remoteViews ; Notification notification ; public static PowerManager powerManger ; public static WakeLock wakeLock ; static volatile int connectionState ; public static int watchType ; public static int watchState ; public static TestSmsLoop testSmsLoop ; private boolean lastConnectionState = false ; final class ConnectionState { static final int DISCONNECTED = 0 ; static final int CONNECTING = 1 ; static final int CONNECTED = 2 ; static final int DISCONNECTING = 3 ; } final class WatchBuffers { static final int IDLE = 0 ; static final int APPLICATION = 1 ; static final int NOTIFICATION = 2 ; } final class WatchStates { static final int OFF = 0 ; static final int IDLE = 1 ; static final int APPLICATION = 2 ; static final int NOTIFICATION = 3 ; static final int CALL = 3 ; } static class WatchModes { public static volatile boolean IDLE = false ; public static volatile boolean APPLICATION = false ; public static volatile boolean NOTIFICATION = false ; public static volatile boolean CALL = false ; } static class Preferences { public static boolean notifyCall = true ; public static boolean notifySMS = true ; public static boolean notifyGmail = true ; public static boolean notifyK9 = true ; public static boolean notifyAlarm = true ; public static boolean notifyBatterylow = true ; public static boolean notifyMusic = true ; public static boolean notifyCalendar = true ; public static String watchMacAddress = "" ; public static int packetWait = 10 ; public static boolean skipSDP = false ; public static boolean invertLCD = false ; public static String weatherCity = "Dallas,US" ; public static boolean weatherCelsius = false ; public static int fontSize = 2 ; public static int smsLoopInterval = 15 ; public static boolean idleMusicControls = false ; public static boolean idleReplay = false ; public static boolean disableWeather = false ; } final class WatchType { static final int ANALOG = 1 ; static final int DIGITAL = 2 ; } @ Override public IBinder onBind ( Intent intent ) { } public static void loadPreferences ( Context context ) { } public static void saveMac ( Context context , String mac ) { } public void createNotification ( ) { } private PendingIntent createNotificationPendingIntent ( ) { } public void updateNotification ( ) { } public void removeNotification ( ) { } @ Override public void onCreate ( ) { } @ Override public void onDestroy ( ) { } void connect ( Context context ) { try { Log . d ( TAG , ( "Remote<seq2seq4repair_space>device<seq2seq4repair_space>address:<seq2seq4repair_space>" + ( MetaWatchService . Preferences . watchMacAddress ) ) ) ; if ( MetaWatchService . Preferences . watchMacAddress . equals ( "" ) ) MetaWatchService . loadPreferences ( context ) ; BluetoothDevice bluetoothDevice = MetaWatchService . bluetoothAdapter . getRemoteDevice ( MetaWatchService . Preferences . watchMacAddress ) ; if ( ! ( MetaWatchService . bluetoothAdapter . isEnabled ( ) ) ) { return ; } if ( MetaWatchService . Preferences . skipSDP ) { Method method = bluetoothDevice . getClass ( ) . getMethod ( "createRfcommSocket" , new Class [ ] { int . class } ) ; bluetoothSocket = ( ( BluetoothSocket ) ( method . invoke ( bluetoothDevice , 1 ) ) ) ; } else { UUID uuid = UUID . fromString ( "00001101-0000-1000-8000-00805F9B34FB" ) ; bluetoothSocket = bluetoothDevice . createRfcommSocketToServiceRecord ( uuid ) ; } bluetoothSocket . connect ( ) ; MetaWatchService . inputStream = bluetoothSocket . getInputStream ( ) ; MetaWatchService . outputStream = bluetoothSocket . getOutputStream ( ) ; MetaWatchService . connectionState = MetaWatchService . ConnectionState . CONNECTED ; updateNotification ( ) ; Protocol . startProtocolSender ( ) ; Protocol . sendRtcNow ( context ) ; Protocol . getDeviceType ( ) ; Notification . startNotificationSender ( this ) ; if ( MetaWatchService . Preferences . idleReplay ) Protocol . enableReplayButton ( ) ; else Protocol . disableReplayButton ( ) ; SharedPreferences sharedPreferences = PreferenceManager . getDefaultSharedPreferences ( context ) ; <START_BUG> boolean notifyOnConnect = sharedPreferences . getBoolean ( "NotifyWatchOnConnect" , false ) ; <END_BUG> Log . d ( TAG , ( "MetaWatchService.connect():<seq2seq4repair_space>notifyOnConnect=" + notifyOnConnect ) ) ; if ( notifyOnConnect ) { NotificationBuilder . createOtherNotification ( context , "MetaWatch" , "Connected" ) ; } } catch ( IOException ioexception ) { Log . d ( TAG , ioexception . toString ( ) ) ; } catch ( SecurityException e ) { Log . d ( TAG , e . toString ( ) ) ; } catch ( NoSuchMethodException e ) { Log . d ( TAG , e . toString ( ) ) ; } catch ( IllegalArgumentException e ) { Log . d ( TAG , e . toString ( ) ) ; } catch ( IllegalAccessException e ) { Log . d ( TAG , e . toString ( ) ) ; } catch ( InvocationTargetException e ) { Log . d ( TAG , e . toString ( ) ) ; } } public void sendToast ( String text ) { } private Handler messageHandler = new Handler ( ) { @ Override public void handleMessage ( Message msg ) { } } ; void disconnect ( ) { } void disconnectExit ( ) { } void start ( ) { } void readFromDevice ( ) { } void broadcastConnection ( boolean connected ) { } void pressedButton ( byte button ) { } void broadcastButton ( byte button , int state ) { } }

Fix:
boolean notifyOnConnect = sharedPreferences . getBoolean ( "NotifyWatchOnConnect" , true ) ;