Вопрос

I'm trying to integrate dropbox upload in my app. I've read the official examples and I was able to write a client to upload the files. Now there is just one thing that I'd like to fix.. the example first run this line of code:

mDBApi.getSession().startOAuth2Authentication(MainActivity.this);

and then use OnResume to complete the auth:

protected void onResume() {
    super.onResume();
    if (mDBApi.getSession().authenticationSuccessful()) {
        try {
            // Required to complete auth, sets the access token on the session
            mDBApi.getSession().finishAuthentication();

            String accessToken = mDBApi.getSession().getOAuth2AccessToken();
        } catch (IllegalStateException e) {
            Log.i("DbAuthLog", "Error authenticating", e);
        }
    }
    new myOperation().execute("");
}

This works, but I was looking for a way to replace the onResume (that is also called when the app start and cause some exceptions). Is there a way to call a function when the mDBApi.getSession().startOAuth2Authentication(MainActivity.this); ends ?

Thanks for the help, and as usual, if you need further infos please ask

Это было полезно?

Решение

if this is the only way available by the API, then you have to use it if you have a control over what startOAuth2Authentication do, you can use startActivityForResult() , but its inside API you can't change it.

so i would suggest you handle whatever exceptions you get at onResume() by using some validations, like wrapping whole code inside onResume() with this

if(mDBApi!=null){...
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top