parse-community / Parse-SDK-Android

The Android SDK for Parse Platform
https://parseplatform.org/
Other
1.88k stars 739 forks source link

What to use as an alternative to the deprecated `onActivityResult` method? #1144

Closed Code-B1 closed 2 years ago

Code-B1 commented 2 years ago

New Issue Checklist

Issue Description

I have noticed that when implementing the Facebook login that we are still having to overrideOnActivityResult() however, this has since been deprecated (it appears as if it still works for now however, I assume not for much longer).

I was wondering if there was a new login method available that we can use ? which avoids overriding this method ? or am I possibly using the incorrect method ? (I am currently using ParseFacebookUtils.logInWithReadPermissionsInBackground as per the documentation)

I wonder if you may be able to assist ? or advise if this method is still safe to use moving forward.

Steps to reproduce

Use ParseFacebookUtils.logInWithReadPermissionsInBackground to log into Facebook and override OnActivityResult()

Actual Outcome

I notice when I override the OnActivityResult() that there is a strikethrough this method (though it does appear to work)

Expected Outcome

To not be using any deprecated methods to log into Facebook

Parse Android SDK

parse-github-assistant[bot] commented 2 years ago

Thanks for opening this issue!

azlekov commented 2 years ago

Hey @Code-B1 thanks for opening this. Indeed starting from AndroidX Fragment 1.3 they deprecated the Fragment::onActivityResult in flavour of the new Activity Result APIs.

From what I understood the problem is not in the ParseFacebookUtils method (as there's no deprecations there) but in your Activity/Fragment. In this case you should update your code and start using the activity result APIs. A quick research gives a very nice StackOverflow topic where you can find how to do it.

I have created an issue on the documentation repo. If you're interested you can create a PR to help others not get confused. 😊🤞

Good luck, Assen

mtrezza commented 2 years ago

I'm closing this; we could have transferred this issue to the docs repo, but since there is a new issue there, I reclassified this as a support question that requires no further action.

Code-B1 commented 2 years ago

@L3K0V Thank you for the prompt response, I had found this article also when trying to research this however, I was unable to adopt this to work for the facebook login, (I apologise, as this is likely due to me being very new to Kotlin) however I cannot seem to find a way to get this to fire in the correct order.

The old method utilizes the onActivityResult when ParseFacebookUtils.logInWithReadPermissionsInBackground is run, however, the StackOverflow suggestion requires passing an activity to the launcher (rather than a method). When I pass the activity containing my login activity it is unable to complete as it needs ParseFacebookUtils.onActivityResult method to be run as part of the login activity which is before the activity is finished (if that makes sense).

I assume a lot of my confusion is down to my lack of knowledge in Kotlin, as I cannot seem to work out an alternative way to get the data returned from ParseFacebookUtils.logInWithReadPermissionsInBackground into the registerForActivityResultas I assume the logic from the when statement would now have to be moved into the registerForActivityResult to occur after this has ran.

Unfortunately, this means I won't be able to help with a PR :( but I will definitely be looking forward to the updated documentation when it becomes available. Until then I shall keep pursuing trying to get this working :(