I wonder if someone may be able to assist with my struggles, I apologise as I’m new to Kotlin.
After implementing facebook login following the parse-sdk-android
documentation I have realised that onActivityResult()
is deprecated (though it still works for the timebeing).
I am trying to adapt my code to work with the new Activity Result API’s (I saw a previous suggestion to use registerForActivityResult
) however, my issue is that we are only calling the method ParseFacebookUtils.logInWithReadPermissionsInBackground
in the code and the activity being called is nested within this method.
I attempted to use registerForActivityResult
to start the activity containing this method however it will only capture the result of the activity started and not that of the nested activity within ParseFacebookUtils.logInWithReadPermissionsInBackground
(which is the expected behaviour). Online searches have not brought back any results for a way to implement this for parse-sdk-android
.
So my question is whether there is a way to capture the result of the nested activity using just the method ? without being able to change the nested code.
My code for logging in currently is as below:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
loginFacebook()
}
private fun loginFacebook(){
val permissions: List<String> = listOf("public_profile", "email")
ParseFacebookUtils.logInWithReadPermissionsInBackground(this,permissions) { user: ParseUser?, err: ParseException? ->
when {
err != null -> {
Log.e("FacebookLoginExample", "done: ", err)
Toast.makeText(this, err.message, Toast.LENGTH_LONG).show()
}
user == null -> {
Toast.makeText(this, "The user cancelled the Facebook login.", Toast.LENGTH_LONG).show()
Log.d("FacebookLoginExample", "Uh oh. The user cancelled the Facebook login.")
}
user.isNew -> {
Toast.makeText(this, "User signed up and logged in through Facebook.", Toast.LENGTH_LONG).show()
Log.d("FacebookLoginExample", "User signed up and logged in through Facebook!")
getUserDetailFromFB()
}
else -> {
Toast.makeText(this, "User logged in through Facebook.", Toast.LENGTH_LONG).show()
Log.d("FacebookLoginExample", "User logged in through Facebook!")
showAlert("Oh, you!", "Welcome back!")
}
}
}
}