googleworkspace / android-samples

Android samples for Google Workspace APIs
Apache License 2.0
635 stars 410 forks source link

Connect/disconnect during onStart/onStop or onResume/onPause? #48

Closed hidroh closed 6 years ago

hidroh commented 8 years ago

Hi, according to Android documentation, onStart/onStop are the callbacks for when Activity starts to be visible/invisible, and onResume/onPause are for when Activity is in foreground or not. This is especially true for Android N in split screen mode, when Activity may be paused but still visible. With that in mind, should we connect/disconnect API client during onStart/onStop instead of onResume/onPause as in BaseDemoActivity?

asrivas commented 6 years ago

I'd recommend onResume/onPause because you want to handle clean up here:

"onPause() is where you deal with the user leaving your activity. Most importantly, any changes made by the user should at this point be committed (usually to the ContentProvider holding the data)." https://developer.android.com/reference/android/app/Activity

Also in cases of low memory the system might kill paused activities so you'd probably want to have cleaned up.