Android app crashes without any exception, when trying to sign in with Google plus

android, android-memory, debugging, google-api, google-play-services

Solution

Remove `android:noHistory="true"` from the `<activity>` definition of `LoginActivity` in your manifest. I'm pretty sure that the `noHistory` setting causes Android to finish the `LoginActivity` when it starts the Google+ signin activity. Since the activity is already finished, there won't be anything there to call `onActivityResult()` on. Your app isn't actually crashing, it is just done.

If you want to make sure that the user doesn't BACK into your `LoginActivity` you will have to solve that problem in another way (override `onBackPressed()` or something else).

Problem

I'm developing an app, which has a LoginActivity with a Google plus sign-in button. I've already Enabled the Google+ API in Google's api console and made an Oauth account. Here is the relevant part of my code: activity class declaration: ``` public class LoginActivity extends Activity implements OnClickListener, ConnectionCallbacks, OnConnectionFailedListener, PlusClient.OnAccessRevokedListener { private PlusClient mPlusClient; private ConnectionResult mConnectionResult; private static final int REQUEST_CODE_SIGN_IN = 2 ``` onCreate: ``` protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_login); mPlusClient = new PlusClient.Builder(this, this, this) .setActions("http://schemas.google.com/AddActivity").build(); ``` onClick: ``` public void onClick(View view) { Utils.LOGD("onClick - View = " + view); if (view.getId() == R.id.sign_in_button) { Utils.LOGD("onClick : mPlusClient status = " + mPlusClient); if (mPlusClient.isConnected()) { Utils.LOGD("onClick - mPlusClient is connected"); Toast.makeText(this, "you are already signed in!", Toast.LENGTH_LONG).show(); } else { Utils.LOGD(" mConnectionResult before trying to connect = " + mConnectionResult); if (mConnectionResult == null) { return; } try { mConnectionResult.startResolutionForResult(LoginActivity.this, REQUEST_CODE_SIGN_IN); } catch (IntentSender.SendIntentException e) { Utils.LOGD( "Exception caught : ) " + e.getMessage()) ; mPlusClient.connect(); } } ``` onActivityResult : ``` @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == REQUEST_CODE_SIGN_IN) { if (resultCode == RESULT_OK && !mPlusClient.isConnected() && !mPlusClient.isConnecting()) { // This time, connect should succeed. mPlusClient.connect(); Utils.LOGD("onActivityResult : mConnectionResult AFTER trying to connect = " + mConnectionResult); Utils.LOGD(" onActivityResult result code = " + resultCode); } } } ``` The problem is after I click the sign in button and Google's built in "loading.." progress bar shows, the app suddenly quits to the phone's main screen, without any error showing on the device itself NOR the in the logcat! Also, when I come back to the app after it crashed, I see that the sign-in has finished successfully, onConnected has been called, and I am logged in with my Google account. (I have an editText showing my name after sign in) This happens almost every time I click the button ' but not always. I've also noticed that when running the app on an emulator this crash almost never happens. (though it happened few times ) I also added logs to see when onConnected onStop and onDestroy are called here is the logcat from when I click sign-in, to immediately after the crash: ``` 12-04 17:54:37.464 6516-6516/com.meeba.google D/debug﹕ onClick - View = com.google.android.gms.common.SignInButton@415ea1f8 12-04 17:54:37.464 6516-6516/com.meeba.google D/debug﹕ onClick : mPlusClient status = com.google.android.gms.plus.PlusClient@41570e18 12-04 17:54:37.468 6516-6516/com.meeba.google D/debug﹕ mConnectionResult before trying to connect = ConnectionResult{statusCode=SIGN_IN_REQUIRED, resolution=PendingIntent{4164c2a8: android.os.BinderProxy@41571528}} 12-04 17:54:37.472 195-360/system_process I/ActivityManager﹕ START {cmp=com.google.android.gms/.plus.activity.AccountSignUpActivity (has extras)} from pid -1 12-04 17:54:37.550 6516-6516/com.meeba.google D/debug﹕ onPause 12-04 17:54:37.550 6516-6516/com.meeba.google D/debug﹕ onPause: mPlusClient.isConnected = false 12-04 17:54:37.550 6516-6516/com.meeba.google D/debug﹕ onPause: mPlusClient.isConnecting = false 12-04 17:54:37.589 195-441/system_process I/ActivityManager﹕ START {act=com.google.android.gms.common.account.CHOOSE_ACCOUNT cmp=com.google.android.gms/.common.account.AccountPickerActivity (has extras)} from pid 6544 12-04 17:54:37.789 195-197/system_process D/dalvikvm﹕ GC_CONCURRENT freed 816K, 25% free 13321K/17671K, paused 10ms+11ms 12-04 17:54:37.793 195-227/system_process I/ActivityManager﹕ Displayed com.google.android.gms/.plus.activity.AccountSignUpActivity: +235ms 12-04 17:54:37.937 1199-1210/com.google.android.gsf.login D/dalvikvm﹕ GC_EXPLICIT freed 144K, 7% free 9315K/9927K, paused 1ms+4ms 12-04 17:54:38.187 6544-6546/com.google.android.gms.ui D/dalvikvm﹕ GC_CONCURRENT freed 267K, 4% free 9530K/9927K, paused 2ms+16ms 12-04 17:54:38.211 195-3148/system_process W/InputManagerService﹕ Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@415115c8 12-04 17:54:38.312 631-634/com.google.android.gms D/dalvikvm﹕ GC_CONCURRENT freed 530K, 8% free 10775K/11591K, paused 2ms+15ms 12-04 17:54:38.351 6544-6544/com.google.android.gms.ui D/OpenGLRenderer﹕ Flushing caches (mode 0) 12-04 17:54:38.371 6544-6544/com.google.android.gms.ui D/OpenGLRenderer﹕ Flushing caches (mode 0) 12-04 17:54:38.375 6516-6516/com.meeba.google D/debug﹕ onStop 12-04 17:54:38.375 6516-6516/com.meeba.google D/debug﹕ onDestroy 12-04 17:54:38.418 6516-6516/com.meeba.google D/OpenGLRenderer﹕ Flushing caches (mode 1) ``` and this is the logcat after returning to the app ``` 12-04 17:59:21.828 195-441/system_process I/ActivityManager﹕ START {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.meeba.google/.activities.LoginActivity bnds=[240,405][360,556]} from pid 406 12-04 17:59:21.988 6516-6516/com.meeba.google D/debug﹕ mPlusClient = :com.google.android.gms.plus.PlusClient@416af6d8 12-04 17:59:21.992 6516-6516/com.meeba.google D/debug﹕ onCreate finished 12-04 17:59:21.996 6516-6516/com.meeba.google D/debug﹕ onStart 12-04 17:59:22.003 406-406/com.cyanogenmod.trebuchet D/OpenGLRenderer﹕ Flushing caches (mode 1) 12-04 17:59:22.019 6516-6518/com.meeba.google D/dalvikvm﹕ GC_CONCURRENT freed 406K, 5% free 12419K/12999K, paused 2ms+4ms 12-04 17:59:22.019 6516-6516/com.meeba.google D/debug﹕ onResume 12-04 17:59:22.078 406-406/com.cyanogenmod.trebuchet D/OpenGLRenderer﹕ Flushing caches (mode 0) 12-04 17:59:22.230 195-209/system_process D/dalvikvm﹕ GC_EXPLICIT freed 780K, 25% free 13351K/17671K, paused 3ms+12ms 12-04 17:59:22.355 631-634/com.google.android.gms D/dalvikvm﹕ GC_CONCURRENT freed 524K, 8% free 10777K/11591K, paused 3ms+4ms 12-04 17:59:22.378 195-209/system_process I/Process﹕ Sending signal. PID: 6516 SIG: 3 12-04 17:59:22.378 6516-6520/com.meeba.google I/dalvikvm﹕ threadid=3: reacting to signal 3 12-04 17:59:22.382 6516-6520/com.meeba.google I/dalvikvm﹕ Wrote stack traces to '/data/anr/traces.txt' 12-04 17:59:22.429 195-227/system_process I/ActivityManager﹕ Displayed com.meeba.google/.activities.LoginActivity: +553ms 12-04 17:59:22.640 6544-6544/com.google.android.gms.ui D/OpenGLRenderer﹕ Flushing caches (mode 1) 12-04 17:59:22.660 631-711/com.google.android.gms I/qtaguid﹕ Failed write_ctrl(u 90) res=-1 errno=22 12-04 17:59:22.683 6544-6546/com.google.android.gms.ui D/dalvikvm﹕ GC_CONCURRENT freed 458K, 7% free 9478K/10119K, paused 1ms+3ms 12-04 17:59:22.683 631-711/com.google.android.gms I/qtaguid﹕ Untagging socket 90 failed errno=-22 12-04 17:59:22.683 631-711/com.google.android.gms W/NetworkManagementSocketTagger﹕ untagSocket(90) failed with errno -22 12-04 17:59:22.707 6516-6516/com.meeba.google D/debug﹕ onConnected started 12-04 17:59:22.707 6516-6516/com.meeba.google D/debug﹕ mPlusClient in onConnected is =com.google.android.gms.plus.PlusClient@416af6d8 ``` After debugging I saw that the app crashes exactly at the line mConnectionResult.startResolutionForResult(LoginActivity.this, REQUEST_CODE_SIGN_IN) What is wrong or what should I do? edited: added the manifest.xml ``` <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.meeba.google" android:versionCode="1" android:versionName="1.0" > <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.GET_ACCOUNTS" /> <uses-permission android:name="android.permission.USE_CREDENTIALS" /> <uses-permission android:name="android.permission.READ_CONTACTS" /> <uses-permission android:name="android.permission.WAKE_LOCK" /> <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> <permission android:name="com.meeba.google.permission.C2D_MESSAGE" android:protectionLevel="signature" /> <uses-permission android:name="com.meeba.google.permission.C2D_MESSAGE" /> <uses-sdk android:minSdkVersion="9" android:targetSdkVersion="18" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:debuggable="true" android:largeHeap="true" android:theme="@style/Theme.Sherlock.Light" > <receiver android:name=".GcmBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND" > <intent-filter> <action android:name="com.google.android.c2dm.intent.RECEIVE" /> <action android:name="com.google.android.c2dm.intent.REGISTRATION" /> <category android:name="com.meeba.google" /> </intent-filter> </receiver> <service android:name=".GcmIntentService" android:enabled="true" /> <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" /> <activity android:name=".activities.LoginActivity" android:label="@string/app_name" android:noHistory="true"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".activities.DashboardActivity" > <!--intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter--> </activity> <activity android:name=".activities.WhereWhenActivity" /> <activity android:name=".activities.ContactsActivity" android:windowSoftInputMode="stateHidden"/> <activity android:name=".activities.InvitationActivity" /> <activity android:name=".activities.EventPageActivity" /> </application> </manifest> ```

Original source