Questions tagged [fragment-lifecycle]

Covers how and when the lifecycle callback methods like onAttach, onCreateView etc. are being called when the fragment is created, destroyed, recreated or put in the backStack.

150 questions
0
votes
2 answers

Restore fragment state after ActivityResult

I'm working on a fragment which displays a list of images. It has a button for "add image" that starts an intent for result with these values. type: "image/*" action: Intent.ACTION_GET_CONTENT The problem is: after the user picks an image and…
user8738866
0
votes
0 answers

Why fragment still keep it memory address when the fragment is destroyed

I try to log all of fragment life-cycle inside viewpager which using StateFragmentAdapter.Fragment A move to fragment C and it logged that fragment A is onDestroy and onDestroyView.but when i return to fragment A,the memory addresss of that fragment…
shadow
  • 114
  • 11
0
votes
0 answers

Fragment global variable not being remove when destroy fragment-activity

I used to think that all of global variable is destroy it self when fragment is destroy (in onDestroy) or maybe sometime it will removed by Garbage Collector.But when trying to check the variable instance in onDestroy,it not be clean up by…
0
votes
0 answers

Preference Fragment onPause() & onResume() not getting called

While adding a new fragment in a back-stack from preference fragment, the Preference fragment life-cycle events onPause() & onResume() is not getting called, when a new fragment is added on top of it. Due to this, I am not able to update the summary…
0
votes
0 answers

Multiple Buttons on Android Fragment

In a fragment when buttons are clicked on, they will open different fragment. When signup_b is clicked, new fragment is opened but when signin_b is clicked new fragment is not opened. public void onViewCreated(final View view, @Nullable Bundle…
0
votes
1 answer

Kotlin : create content in onCreateView

I'm generating some content thanks to my function getInfoTrafic(). But when I display it on my screen, my screen is load and after (like a second), my content is generated. Why? Is that normal for a fragment? Is it possible to do what I…
0
votes
1 answer

Statically added Fragment can't restore instance state?

when i add a Fragment statically in the Activity layout, i can't seem to be able to recover the state in onViewStateRestored(savedInstanceState: Bundle) even though onSaveInstanceState(outState: Bundle) is called correctly. It works for the same…
0
votes
1 answer

Fragment saves previous state but it doesn't restore correctly

I have an actviity which loads a fragment in the onCreate like this: @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); loadFragment(new…
0
votes
2 answers

Fragment Lifecycle

I'm trying to understand the internal behavior of Android fragments. Got doubts between exact difference between onDestroy(), onDetach() and void onDestroy () Called when the fragment is no longer in use. This is called after onStop() and before…
kavie
  • 2,154
  • 4
  • 28
  • 53
0
votes
0 answers

Can getContext() be null in this flow?

If I have an onClickListener that is called when user clicks on a button and that listener does a callback to a method of the containing fragment which does getContext(). Is there a case that the getContext() in this sequence could return null? I am…
0
votes
0 answers

Attributes in fragment becomes null on minimization and return with "Don't keep activities" on

I have a fragment where I use a button and in the onCreateView() call the button. I declare these attributes in the Fragment: Button button; Carrier carrier; In the onCreateView() method I assign values to them: button…
0
votes
0 answers

Which callback should be used to detect android fragment removed from screen and it is not visible anymore

I use a FragmentTransaction to show my fragment inside my activity and also I add it to backstack like this: getSupportFragmentManager().beginTransaction() .addToBackStack(null) .setCustomAnimations(R.anim.enter_from_left,…
VSB
  • 9,825
  • 16
  • 72
  • 145
0
votes
1 answer

android.app.Application cannot be cast to android.support.v4.app.FragmentActivity on clcik

I have a class that implentss RecyclerView.Adapter and am callingonClick listener inside onBindViewHolder to access another Fragment. I have this error persist and points back to context. code snipet below…
Mbanda
  • 968
  • 11
  • 21
0
votes
0 answers

Getting data from MainActivity and handling it in Fragment

I have a problem while getting data from MainActivity and handle it on Fragment. At first, there are 4 Fragments. I am using TabLayout and ViewPager. Whenever a fragment selected from the Tab, it triggers onPageSelected() method. Here, I instantiate…
0
votes
1 answer

In which life cycle do I have to set data in my view pager (is a fragment) that I get from a retrofit response?

I have a view pager that is a fragment. Inside this, I have three fragments each one show a list of items that have the same model but filtered by one state (property in my model), for example like whatsapp that I have one list for all my…