문제

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