private ServiceConnection mConnection = new ServiceConnection() { public void onServiceConnected(ComponentName className, IBinder binder) { Toast.makeText(MainActivity.this, "Connected to the service", Toast.LENGTH_SHORT) .show(); } public void onServiceDisconnected(ComponentName className) { Toast.makeText(MainActivity.this, "Disconnected from the service", Toast.LENGTH_SHORT) .show(); } };