When developing for Android, if the API you need is available in the [Google Play Services library], use that for optimal performance. For all other Google APIs, use the Google APIs Client Library for Java's Android-specific helper classes. These classes integrate with the Android AccountManager for identity management.
To initialize a service, use GoogleAccountCredential.usingOAuth2() to create credentials and then pass them to the service's Builder.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Google Accounts
credential = GoogleAccountCredential.usingOAuth2(this, Collections.singleton(TasksScopes.TASKS));
SharedPreferences settings = getPreferences(Context.MODE_PRIVATE);
credential.setSelectedAccountName(settings.getString(PREF_ACCOUNT_NAME, null));
// Tasks client
service = new com.google.api.services.tasks.Tasks.Builder(httpTransport, jsonFactory, credential)
.setApplicationName("Google-TasksAndroidSample/1.0").build();
}