E-Place E-Place - 4 months ago 24
Android Question

android force stop when click logout from google sign-in

android force stop when click logout from google sign-in.

when in my app user click on logout button then i call function confirmationbox, if user click

ya
or
ok
so user will logout but now it force stop when user click
ya
or
ok


this my code

private void confirmationBox() {
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Apakah Anda Yakin?")
.setCancelable(false)
.setPositiveButton("Ya", new DialogInterface.OnClickListener() {
public void onClick(@SuppressWarnings("unused") final DialogInterface dialog, @SuppressWarnings("unused") final int id) {
Auth.GoogleSignInApi.revokeAccess(mGoogleApiClient).setResultCallback(
new ResultCallback<Status>() {
@Override
public void onResult(Status status) {

}
});
session.logoutUser();
Intent intent = new Intent(getApplicationContext(),LoginActivity.class);
startActivity(intent);
finish();
}
})
.setNegativeButton("Tidak", new DialogInterface.OnClickListener() {
public void onClick(final DialogInterface dialog, @SuppressWarnings("unused") final int id) {
dialog.cancel();
}
});
final AlertDialog alert = builder.create();
alert.show();
}


GoogleSignInOption

private void setGoogleSignInAccount() {
// Configure sign-in to request the user's ID, email address, and basic profile. ID and basic profile are included in DEFAULT_SIGN_IN.
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.build();

// Build a GoogleApiClient with access to the Google Sign-In API and the options specified by gso.
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
}


and this is my logcat

07-17 10:47:55.871 26064-26064/com.emergency.e_place E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.emergency.e_place, PID: 26064
java.lang.NullPointerException: Appropriate Api was not requested.
at com.google.android.gms.common.internal.zzx.zzb(Unknown Source)
at com.google.android.gms.common.api.internal.zzj.zza(Unknown Source)
at com.google.android.gms.common.api.internal.zzg.zza(Unknown Source)
at com.google.android.gms.common.api.internal.zzg.zzb(Unknown Source)
at com.google.android.gms.common.api.internal.zzl.zzb(Unknown Source)
at com.google.android.gms.common.api.internal.zzj.zzb(Unknown Source)
at com.google.android.gms.auth.api.signin.internal.zzc.revokeAccess(Unknown Source)
at com.emergency.e_place.MainActivity$10.onClick(MainActivity.java:832)
at android.support.v7.app.AlertController$ButtonHandler.handleMessage(AlertController.java:153)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5511)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)

Answer

You are missing the Sign In API. This line should be in your code.

.addApi(Auth.GOOGLE_SIGN_IN_API

Refer to how to setup the Sign In API

Comments