Android Studio Facebook: onActivityResult in normal class - java

In order to listen to a facebook login event I must override in my activity the function onActityResult and make a call to facebook's callbackmanager.
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
callbackManager.onActivityResult(requestCode, resultCode, data);
}
So far everything's working.
I'd like to create a static class for facebook that handles facebook callbacks, such as login, etc.
Is there substitute for onActivityResult in that case?

You mean you want another class to handle the activity returning? Then you have to have onActivityResult of the activity that calls startActivityForResult call into your facebook class. There's no way to reroute it automatically.

Related

How to get setup result from stripe in a Fragment?

How do i get the response from stripe with the new Activity Result Api? I create a new card and i want to attach it to a stripe account. To do that i have to use the confirm setup intent and wait for the answer from stripe. But how do i register this one with the new Api? This is my code and but the onActivityResult has been deprecated now. I know how to use it for picking images or making phone calls and other that can use the launch function of the register activity. I don't want to do this on the server side because if the card needs 3D secure webview stripe handles that automatically.
ConfirmSetupIntentParams confirmParams = ConfirmSetupIntentParams
.create(paymentMethodParams, clientSecret);
stripe.confirmSetupIntent(this, confirmParams);
#Override
public void onActivityResult(int requestCode, int resultCode, #org.jetbrains.annotations.Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
stripe.onSetupResult(requestCode, data, new ApiResultCallback<SetupIntentResult>() {

How to close intent opened on startActivityForResult

My app uses accessibility, i have opened the intent with startActivityForResult(new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS),500); and handled result onActivityResult(int requestCode, int resultCode, Intent data) {} but the problem the accessibility intent is not returning /self closing back to my app which promoted me to use finish() to act like am pressing back key button but no avail... whats the solution ?

StartActivityForResult, but activity finishes

I am trying to use Adobe Image Edit SDK to edit a photo then redirect to another activity, from my custom camera activity.
This works from another activity, simply by creating the Image edit Intent, using startActivityForResult, then treating the "Done" callback in said activity, in the method onActivityResult.
Intent imageEditorIntent = new AdobeImageIntent.Builder(mContext)
.setData(selectedImageUri)
.withToolList(tools)
.withOutput(new File(mLastSavedFilePath))
.build();
startActivityForResult(imageEditorIntent, 2);
and then
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
if (requestCode == 2) { // i get here
However, when I do this from my Custom Camera Activity, the activity ends when I click "done" in the image edit sdk (its onDestroy is called) before it gets to the result
Intent intent = FileUtils.getInstance().SavePhoto(data, mContext); //this returns an AdobeImageIntent
startActivityForResult(intent, 1);
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
//this never gets called, because activity finishes, but why?
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
So why is the activity finishing, if the other one does not?
Turns out this was my fault, I did not notice I had android:noHistory="true"
in the manifest for the second activity

onActvityResult still broken?

I have an issue where onActivityResult is not being called back in my fragment.
I am starting the activity from my ListFragment as so:
Intent getJobDetailIntent = new Intent(getActivity(),FullJobdetailLayoutActivity.class);
startActivityForResult(getJobDetailIntent,100);
Now I override and set a breakpoint in my fragments onActivityResult,
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data){
Log.d("ActivityResult FullJobDetailActivity: ", "Called");
}
This is never called in my fragment, onActivityResult is called in my Activity though:
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
}
Even letting this call super as above, doesn't work...
I have seen some issues online:
https://code.google.com/p/android/issues/detail?id=15394
And read through a lot of questions on SO regarding this issue....
Does anyone know if it is still a bug?
I need to get data back from the activity started by my fragment!
Thanks all!

setResult does not work on #EActivity

I am trying to setResult on my "Register" Button, but nothing happens:
SignInActivity:
Start activity for result:
Intent intent = RegisterActivity_.intent(this).get();
this.startActivityForResult(intent, REQUEST_CODE_USER_REGISTER);
On Activity Result
#OnActivityResult(REQUEST_CODE_USER_REGISTER)
protected void onResult(int resultCode) {
if (resultCode == RESULT_OK)
DashboardActivity_.intent(this).start();
else if (resultCode == RESULT_CANCELED) {
this.showDialogAlert("Unexpected error", null);
}
RegisterActivity:
this.setResult(RESULT_OK);
I am using AndroidAnnotations and I'm not using the this.finish() method because it set the property android:noHistory="true" in all Activities on AndroidManifest.xml. I am also setting the parent of each activity there. Have tried to remove these settings and setResult continued without work. Has anyone experienced this?
I am using AndroidAnnotations and I'm not using the this.finish() method because it set the property android:noHistory="true"in all Activities on AndroidManifest.xml.
I think your issue is here. When you're using startActivityForRestult, the expected workflow is to launch a new activity, do some work and then close this activity to go back to the previous one with the result of the work. So, you can't use android:noHistory="true" here because it doesn't make any sense.
Also, if you look at Activity's source code, you'll see that result is propagated from the finish method.
Start Activity for Result. your code is Ok
Intent intent = RegisterActivity_.intent(this).get();
this.startActivityForResult(intent, REQUEST_CODE_USER_REGISTER);
Now Inside the Activity that you start for the result set the result status like below code.
setResult(resultCode); result status possible values are like RESULT_CANCELED,RESULT_OK.etc
Activity that starts the new activity for result must override the below method and this method work when the activity that started for result finish.
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
}
I think the method is..
onActivityResult(int requestCode, int resultCode, Intent data)
not onResult

Categories

Resources