FileDocCategorySizeDatePackage
SignoutActivity.javaAPI DocAndroid 1.5 API4085Wed May 06 22:42:46 BST 2009com.android.im.app

SignoutActivity

public class SignoutActivity extends android.app.Activity

Fields Summary
private String[]
ACCOUNT_SELECTION
private ImApp
mApp
private android.os.Handler
mHandler
Constructors Summary
Methods Summary
static voidlog(java.lang.String msg)

        Log.d(ImApp.LOG_TAG, "[Signout] " + msg);
    
protected voidonCreate(android.os.Bundle icicle)


    
        
        super.onCreate(icicle);

        Intent intent = getIntent();
        Uri data = intent.getData();
        if (data == null) {
            Log.e(ImApp.LOG_TAG, "Need account data to sign in");
            finish();
            return;
        }

        ContentResolver cr = getContentResolver();
        Cursor c = cr.query(data,
                ACCOUNT_SELECTION,
                null /* selection */,
                null /* selection args */,
                null /* sort order */);
        final long providerId;
        final long accountId;

        try {
            if (!c.moveToFirst()) {
                Log.w(ImApp.LOG_TAG, "[SignoutActivity] No data for " + data);
                finish();
                return;
            }

            providerId = c.getLong(c.getColumnIndexOrThrow(Im.Account.PROVIDER));
            accountId = c.getLong(c.getColumnIndexOrThrow(Im.Account._ID));
        } finally {
            c.close();
        }

        mApp = ImApp.getApplication(this);
        mApp.callWhenServiceConnected(mHandler, new Runnable() {
            public void run() {
                signOut(providerId, accountId);
            }
        });
    
protected voidonStop()

        super.onStop();

        // always call finish here, because we don't want to be in the backlist ever, and
        // we don't handle onRestart()
        finish();
    
private voidsignOut(long providerId, long accountId)

        try {
            IImConnection conn = mApp.getConnection(providerId);
            if (conn != null) {
                conn.logout();
            } else {
                // Normally, we can always get the connection when user chose to
                // sign out. However, if the application crash unexpectedly, the
                // status will never be updated. Clear the status in this case
                // to make it recoverable from the crash.
                ContentValues values = new ContentValues(2);
                values.put(Im.AccountStatus.PRESENCE_STATUS,
                        Im.Presence.OFFLINE);
                values.put(Im.AccountStatus.CONNECTION_STATUS,
                        Im.ConnectionStatus.OFFLINE);
                String where = Im.AccountStatus.ACCOUNT + "=?";
                getContentResolver().update(Im.AccountStatus.CONTENT_URI,
                        values, where,
                        new String[] { Long.toString(accountId) });
            }
        } catch (RemoteException ex) {
            Log.e(ImApp.LOG_TAG, "signout: caught ", ex);
        } finally {
            finish();
        }