OnCreateView is not called after startActivityForResult () finish () es


I have a fragment that does a startActivityForResult() call in OnCreateView if there is no internet. In the NoInternet Activity there is a retry button that finish()es the activity (So I can supposedly check for connection again). When the activity finishes, OnCreateView of the fragment is never called (because OnCreate() of the host Activity is never called) and I end up not cheking if there is internet again.

Now a simple way around this is to check if there is internet in the OnStart() of the main activity (that hosts the fragment).

But I was wondering: Is there a way to force OnCreateView after finish()ing an Activity that was started with startActivityForResult()?

I think your problem is the understanding of the lifecycle of Fragments. If you call startActivityForResult() on a Fragment, it will be executed on the fragment's containing Activity. Now the Activity goes in the Paused and then Stopped state and also will the Fragment. If you finish the "ResultActivity" the states Started and Resumed will be passed through on the Activity and the Fragment.

So, how you said already, just move your connection checking and your startActivityForResult() call into onStart().

There is no need to create a new view for Fragment. If you want to alter the View programmetically you can do that in onStart() and onResume().

But don't break the lifecycle just for a method call which could be easiely invoked in another callback.