Asynchronous login form handler
Disclaimer: not an android developer....

Thoughts on the Problem

A few thoughts, right off the top.


  In this connection i have an integer field named as state.
  the state value is : 1 for connecting, 2 for connected and 0 for failed


First - that should probably be implemented as an enum, rather than as an integer

Second - that suggests that you are trying to implement a state machine (unsurprising; you are trying to implement a login protocol, and protocols almost always demand state machines).  I'd encourage you to refactor the code and make the state machine explicit; you might want to consider stateless4j as part of the implementation.

Third - doInBackground() needs to be checking for cancellation.  Normally, I would expect that check to be the condition in the while loop.

while (! isCancelled()) {
    if (connection.getState() == ImConnection.LOGGING_IN) {
        ...
    }
}


With the while loop written the way that you have it, it looks as though you are busy spinning while waiting for the state to change.  I'm not keen on that at all; Thread.sleep(), SystemClock.sleep(), something to free up CPU to do the work.  I'd probably go with Thread.sleep() myself, since I would want this worker thread to respond quickly to the cancel() command (which almost certainly interrupts() the running thread).

It's not really clear to me that you need the cancellation to be running on a timer separate from the CheckSignInTask - why not have the task check the time out itself? (If because Reasons[tm], those reasons should be clearly documented in the code so that the next coder to come along doesn't get too clever).

Style notes

What's the point of assigning a member variable if you are only using it in one place?

        protected Boolean doInBackground(IImConnection... params) {
        try {
            IImConnection connection = params[0];


Also, it's disconcerting that you are passed an array of connections, but you only ever manipulate the first one?  

public class TimeOut implements Runnable {
        private AsyncTask task;

        public TimeOut(AsyncTask task) {
            this.task = task;
        }


You planning on changing what task you are timing out later?  Of course not.  So make that explicit

public class TimeOut implements Runnable {
        private final AsyncTask task;
        ...


Try to avoid magic numbers

handler.postDelayed(timeOut, 60 * 1000);


Is that a minute?  A thousand hours? 60 millenia?  

handler.postDelayed(timeOut, TimeUnit.MINUTES.toMillis(1));


or even better

final long LOGIN_PROTOCOL_TIMEOUT = TimeUnit.MINUTES.toMillis(1);
handler.postDelayed(timeOut, LOGIN_PROTOCOL_TIMEOUT);