• Register
0 votes
114 views

Problem :

Now a days I am learning Android Programming. I am facing below error message while trying to implement the logout functionality for the Google Sign-In for the Android:

“Caused by: java.lang.IllegalStateException: GoogleApiClient is not connected yet.”

The crash always occurs in my Java file where I am trying to call the signOut() method.

Below is my java code causing error

private void mygoogleSignOut(){
    myGoogleApiClient = App.getInstance().getClient();
    Auth.GoogleSignInApi.signOut(myGoogleApiClient);
}

I am struggling to find solution on it since yesterday.

2.3k points

Please log in or register to answer this question.

1 Answer

0 votes

Solution :

I know you are learning Android Programming. You can try below solution to fix the error.

I can tell you the actual cause of your error is not at the object creation but it is present at more than one place it is usually found at "enableAutoManage" invocation while Building your Client object.

I have found the required API doc.  it clearly suggests that it will automatically do a life cycle management just by calling the methods on the onStart & onStop methods of your activity.

So if you are planning to use the same object across all the activities then you must avoid calling the "enableAutoManage" and invoke your apiObject.connect(use in onStart of activity) and the apiObject.disconnect() (use in onStop of activity).

This worked for me so I am very sure that it will work for you too.

15.1k points

Related questions

0 votes
1 answer 7 views
7 views
Problem: what I found in StackOverflow is ImportError: No module named API client.discovery I tried to do what people said but it did not work. Please tell me what to do when
asked Jun 25 Isac Christiaan 103k points
0 votes
2 answers 376 views
376 views
Problem: What I am trying to achieve is that I am displaying the view holder inside my Recycler view: Java.lang.illegalstateexception: fragment has not been attached yet.
asked May 3 ochena 23.3k points
0 votes
1 answer 79 views
79 views
problem java.lang.illegalstateexception: already managing a googleapiclient with id 0
asked Feb 9 charles mathews 5.5k points
0 votes
1 answer 138 views
138 views
Problem: I am trying to test my ionic app in android studio. It is throwing the below error. Gradle sync failed: Cause: compileSdkVersion is not specified. Any solution for this ? What am I doing wrong. Here is my build.gradle file apply plugin: ... .test:runner:+' androidTestImplementation 'com.android.support.test.espresso:espresso-core:+' implementation 'com.android.support:appcompat-v7:27.+' }
asked May 3 Yeamin 23.5k points
1 vote
1 answer 87 views
87 views
Problem: I’m getting an error in my code . Here’s the logbox: 01-25 20:42:42.139: E/AndroidRuntime(1307): FATAL EXCEPTION: main 01-25 20:42:42.139: E/AndroidRuntime(1307): java.lang.IllegalStateException: Could not execute method of ... (Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.activity_main, menu); return super.onCreateOptionsMenu(menu); } }
asked May 4 Raj Tyagi 16k points
0 votes
1 answer 48 views
48 views
Problem: user does not have sufficient permissions for this profile.
asked Feb 17 Ethan ross 2.7k points
0 votes
1 answer 23 views
23 views
Problem: It would be great if someone shed some light on it > Client not ready yet..waiting for process to come online
asked May 10 Junia Phoebe 83.8k points
0 votes
1 answer 18 views
18 views
Problem: What is wrong here : Wifi is connected but not working android?
asked Jun 2 Chi Omega 168k points
0 votes
1 answer 316 views
316 views
Problem: Getting this error > com.android.builder.testing.api.deviceexception: no connected devices!
asked Mar 19 Azlan2020 2.5k points
0 votes
1 answer 9 views
9 views
Problem: Hi I am facing this problem please help me with this.Thanks android connected to wifi but no internet
asked Mar 19 PkGuy 25.9k points