FragmentTabHost run Fragment onCreateView after press back - android

I have activity A with FragmentTabHost and activity B. Suppose I go from activity A to activity B via Intent. And then, when I press back button I go to activity A, but Fragment's onCreateView doesn't called. Why? How I can run this method manually?

Related

Restart fragment after back button

I have several fragments that share the same container: Fragment A, Fragment B, Fragment C. I move through them with the .replace method and I always use .addToBackStack to keep them in the stack.
At the current moment, if Fragment C is displayed and I click the Back Button to go back to Fragment B the methods from onCreateView() of Fragment B onwards will be called, but not onAttach or onCreate. I would like to restart Fragment B completely after I click the Back Button so that these methods are also called. In other words, as if I had gone from Fragment B to a different Activity and then back to Fragment B.

what method is called when Actionbar back/home button is pressed?

I have two activities first activity opens on app start and it holds fragment second activity is opened from that fragment, when I press home button second activity closes and in fragment methods onDetach -> onAttach -> onResume is called, but if I close second activity with finish() or onBackPressed() fragment is never detached just onResume() is called.So my question is what method is called when home button is pressed and is there possibility to use same method to close activity for example on button press? Basically what I need is that fragment would call onDetach -> onAttach when I closing second activity.
you can remove the fragment in e.g. onDestroy() of the activity, so the fragment will go through it's lifecycle methods
The activities onPause() is called when pressing the home or back button. I just tried out using finish() and onBackPressed() which results in onPause() being called, too.
However, I am not sure whether there are differences when using fragments.
Android training concerning pausing and resuming: https://developer.android.com/training/basics/activity-lifecycle/pausing.html

Resume Parent Activity

I have 2 Activity A and B, A calls B so, I want to Resume parent Activity (A) when B calls finish() on its Activity. Any advice will be useful.
UPDATE:
Maybe I should mention that I use fragments, each Activity has its own fragment, I call finish() from fragment hosted inside B activity and I expect to receive Resume on fragment belongs to A.
When you call Activity B, Activity A will go to background. Unless you finish Activity A while starting Activity B, it will automatically resume when Activity B finishes.
If you are calling this,
startActivity(ActivityB.class, this);
finish();
Just remove the finish(). It should work as expected.

onDetach not called for fragment?

I write an code to launch Activity A to Activity B. Both Activity A and B has fragment implementation.
Scenario: If Activity A frequently launch Activity B which contain Fragment, then most of times it missed Fragment.onDetach..I checked with log, normally it give me following override method log:
onAttach
List item
OnCreatView
onViewCreate then press device Back Button
onPause
onStop
onDestroyView
onDetach
now I press device Back button from Activity B which again launch Activity A then it launch Activity B and repeat same sequence frequently, then log sequence get change in following order:
onAttach
List item
OnCreatView
onViewCreate then press device Back Button
onPause
onStop
onDestroyView and repeat with
onAttach without onDetach
some times it repeat same behaviour after onPause also.
I am using
getSupportFragmentManager().beginTransaction()
.replace(R.id.fragment_container, fragment).addToBackStack(null).commitAllowingStateLoss(); to add fragment in Activity.
Is there anything I am missing..any suggestion ?
A fragment is detached after it is destroyed. what u have done is dettached directly after destroying view.
Remember destroying and destroying view are two different things in fragment.
So try onDestroyView, then onDestroy and then onDetach.

Android activity navigation issue

I have a problem with navigating through activities. I am navigating from HomeActivity to Activity A. When I move from Home to Activity A, I finish the HomeActivity and starts another activity Activity B. When I start Activity B, I am not finishing Activity A. So when I finish Activity B normally it should go to Activity A. But In my case it is not working. When I call finish() in Activity B, both Activity B and Activity A is getting finished.
Can anybody suggest a way to accomplish this?

Categories

Resources