How to close intent opened on startActivityForResult - java

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 ?

Related

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

Android Studio Facebook: onActivityResult in normal class

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.

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

How to destroy previous activity

So I have 2 activities lets say A and B. A navigates to B, I want the activity A to be killed or make it unusable/unseen when directed from B.
so it should be like when I press the back button on B activity it should not open activity A instead it should go to the app tray.
also activity A should comeback when I clear the application data
thanks.
You could do this in one of two ways. First is finishing ActivityA so that it can't be resumed to later. When starting ActivityB from ActivityA, you'd do something like this:
Intent intent = new Intent(this, ActivityB.class);
startActivity(intent);
this.finish();
Another way is to just finish ActivityA when it gets a result of any sort from ActivityB. This code would also be in ActivityA.
To start ActivityB:
Intent intent = new Intent(this, ActivityB.class);
startActivityForResult(intent, REQUEST_ACTIVITYB);
To make sure ActivityA doesn't resume:
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == REQUEST_ACTIVITYB) {
finish();
}
}
REQUEST_ACTIVITYB is just an int of your choosing.

Categories

Resources