I have code which is working fine for logout of google apiclient, but it left one activity opened after execution, either can some one tell where should I put finish(); to kill that activity or how can I do whole thing in async task. I tried to do with async but got error as client not connected.
Here is code for logout with class extending to activity:
public class GoogleDriveLogoutBackup extends Activity implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {
private static final String TAG = "drive-quickstart";
private GoogleApiClient mGoogleApiClient;
@Override
protected void onStart() {
super.onStart();
if (mGoogleApiClient == null) {
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(Drive.API)
.addScope(Drive.SCOPE_FILE)
.addScope(Drive.SCOPE_APPFOLDER)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
}
mGoogleApiClient.connect();
}
@Override
public void onConnected(Bundle connectionHint) {
Log.d("Connected","Here");
mGoogleApiClient.clearDefaultAccountAndReconnect();
finish();
}
@Override
public void onConnectionSuspended(int i) {
finish();
}
@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
}
}
And here is code which I m using for Async class which I giving me error:
public class GoogleDriveLogout extends AsyncTask<Void, Void, Void> {
private static final String TAG = "drive-quickstart";
private GoogleApiClient mGoogleApiClient;
private Context mcontext;
public GoogleDriveLogout(Context context) {
this.mcontext = context;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
if (mGoogleApiClient == null) {
mGoogleApiClient = new GoogleApiClient.Builder(mcontext)
.addApi(Drive.API)
.addScope(Drive.SCOPE_FILE)
.addScope(Drive.SCOPE_APPFOLDER)
.build();
}
mGoogleApiClient.connect();
}
@Override
protected Void doInBackground(Void... params) {
Log.d("Connected", "Here");
mGoogleApiClient.clearDefaultAccountAndReconnect();
return null;
}
}
I able to did it now by using calling ApiClientAsyncTask which is provided by google itself.