OnActivityResult is called when the Activity starts, and not when it completes.

I wrote FragmentActivity with some tabs. when I call an additional action (which I use to configure user settings) with startActivityForResult (no difference if it is in FragmentActivity or in ListFragment), the onActivityResult method is called when I start this preference activity, but not when I finish it since I would expect this (again, no differences if it is in a FragmentActivity or in a ListFragment). after I finish the preference operation, this method is not called at all.

my problem is that I want to update the current tab (and set the last used tab id) after I have finished the preference activity, and I was hoping I could do it in the onActivityResult method.

this is a class that creates preference activity:

public abstract class ListFragmentBase<I> extends ListFragment implements LoaderCallbacks<List<I>> { 

this is a method that redirects me to preference activity inside this class:

 protected void forwardToPreferences(int currentTab){ Intent intent = new Intent(getActivity(), GlobalPreferencesActivity.class); getActivity().startActivityForResult(intent, 10); } 

this is a method that is called after calling the method above, but not after I finished the called activity

 @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); } 

this preference is activity:

 public class GlobalPreferencesActivity extends Activity { 

and inside this class you see what I call the finish method:

 TextView confirmSettings = (TextView) view.findViewById(R.id.confirm_settings); confirmSettings.setTextSize(PreferenceHelper.getSizeHeader(getApplicationContext())); confirmSettings.findViewById(R.id.confirm_settings).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if(BaseFragmentActivity.lastActivity != null){ BaseFragmentActivity.lastActivity.onRefreshData(); } ComponentName callingActivity = getCallingActivity(); GlobalPreferencesActivity.this.finish(); } }); 
+7
source share
3 answers

This is an Android bug.

onActivityResult () called prematurely

and

Why does the startActivityForResult result begin before the action actually begins?

I do not know which version you are using, and if it has been resolved / fixed.

+3
source

Please make sure that the action of your call is not single in the AndroidManifest file. Make sure it is single point or standard.

Hope this works for you guys too

+7
source

onActivityResult called after onStart,

The main reason is that when you move from your activity to another activity without causing completion. Then the last activity went onStop.

After onStop, the onstart method is called, then onActivityResult is called.

0
source

All Articles