src/com/beem/project/beem/ui/Login.java
changeset 259 a6c3ccc46968
parent 257 5e425cdb07a8
child 263 ff0b4790a5ed
--- a/src/com/beem/project/beem/ui/Login.java	Mon Jun 22 15:37:33 2009 +0200
+++ b/src/com/beem/project/beem/ui/Login.java	Mon Jun 22 15:38:20 2009 +0200
@@ -42,6 +42,8 @@
     private final ServiceConnection mServConn = new BeemServiceConnection();
     private IXmppFacade xmppFacade = null;
 
+    private int REQUEST_CODE = 1;
+
     /**
      * Create an about "BEEM" dialog
      */
@@ -70,7 +72,7 @@
 
 	    @Override
 	    public void onClick(View v) {
-		startActivity(new Intent(Login.this, EditSettings.class));
+		startActivityForResult(new Intent(Login.this, EditSettings.class), REQUEST_CODE);
 	    }
 
 	});
@@ -88,7 +90,8 @@
     @Override
     protected void onDestroy() {
 	super.onDestroy();
-	unbindService(mServConn);
+	if (mIsConnected)
+	    unbindService(mServConn);
     }
 
     /**
@@ -122,33 +125,37 @@
 
 	@Override
 	public void connectionClosed() throws RemoteException {
-	    mIsConnected = false;
-	    Login.this.unbindService(mServConn);
-	    Login.this.stopService(SERVICE_INTENT);
+	    if (mIsConnected) {
+		mIsConnected = false;
+		Login.this.unbindService(mServConn);
+		Login.this.stopService(SERVICE_INTENT);
+	    }
 	}
 
 	@Override
 	public void connectionClosedOnError() throws RemoteException {
-	    mIsConnected = false;
-	    Login.this.unbindService(mServConn);
-	    Login.this.stopService(SERVICE_INTENT);
+	    if (mIsConnected) {
+		mIsConnected = false;
+		Login.this.unbindService(mServConn);
+		Login.this.stopService(SERVICE_INTENT);
+	    }
 	}
 
 	@Override
 	public void connectionFailed(String errorMsg) throws RemoteException {
-	    connectionHandler.post(new ErrorRunnable(errorMsg));
 	    mIsConnected = false;
 	    Login.this.unbindService(mServConn);
 	    Login.this.stopService(SERVICE_INTENT);
+	    connectionHandler.post(new ErrorRunnable(errorMsg));
 	    dismissProgressDialog();
 	    showToast(errorMsg);
 	}
-	
+
 	private void showToast(final String errorMsg) {
 	    connectionHandler.post(new Runnable() {
 		@Override
 		public void run() {
-		    Toast.makeText(Login.this, errorMsg, Toast.LENGTH_SHORT).show();		    
+		    Toast.makeText(Login.this, errorMsg, Toast.LENGTH_SHORT).show();
 		}
 	    });
 	}