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
2
votes
1 answer

API driven app - Nested fragments - where to make API calls ? onStart v/s onCreateView on onResume

My app has a single activity which uses a TabLayout and 1 fragment for each tab's content. Some of these fragments have sub-tabs within and corresponding sub-fragments. Each of these fragments rely on API calls to render their views. I want these…
2
votes
1 answer

Pass onActivityResult() data to the same Fragment which is not yet ready

I am using a Fragment to start a new Activity using startActivityForResult(), I am getting the result (Bundle) in onActivityResult() method.Since onActivityResult() called before onResume().I want to make sure, I keep/save the Bundle properly so…
Brijesh Thakur
  • 6,768
  • 4
  • 24
  • 29
2
votes
2 answers

What is the purpose of a Fragment bundle if the parent Activity bundle always has the objects that are passed to the Fragment?

I have a model inside an Activity, and a Fragment within this Activity needs access to it. I am currently passing it through the Fragment bundle, but why can't I just access it from the Activity within the fragment? For example, I would use this…
clocksmith
  • 6,226
  • 3
  • 32
  • 45
2
votes
1 answer

Handle onResume() not called when recreating fragment from backstack

I recently started refactoring my Android application by replacing "all" activities with fragments. In the state it is right now, it behaves a lot worse than before... My problems are in the area of "up navigation", backstack behaviour and general…
2
votes
1 answer

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,…
2
votes
1 answer

How should I save state of Fragment that contain a listview on android?

In my app there are two fragments and one activity. On all of them I used listview and fill the content from database. When rotate screen the position of content in activity don't change and start on correct way (as I googled and understand it is…
2
votes
1 answer

Is Android fragment argument bundle destroyed in any case?

Default Android Studio generated code: public static Test newInstance(String param1, String param2) { Test fragment = new Test(); Bundle args = new Bundle(); args.putString(ARG_PARAM1, param1); args.putString(ARG_PARAM2, param2); …
Livy
  • 631
  • 4
  • 15
1
vote
1 answer

After two or more screen rotations, lifecycleScope.launchWhenCreated stops working as expected

I have a code like this: private val appViewModel: AppViewModel by activityViewModels() private lateinit var user: User override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) // This…
1
vote
1 answer

How to keep fragment in activity during orientation change?

I have framelayout in activity and two fragments that I need to attach to the activity depending on the user's choise. When I attach one fragment and change orientation, my fragment gest destrotroyed with activity. How to keep the state of fragment…
1
vote
1 answer

replacement method for onNewIntent() in android fragment

I am developing a NFC app using Fragments. the fragment class will not let me use onNewIntent() for me to be able to make the app scan NFC tags. Is there a replacement function or work around to this issue. below are the methods I am using in the…
SLR
  • 45
  • 3
1
vote
1 answer

OnDestroyView and OnResume not called after replacing fragments

I am trying to replace fragment B with fragment A. But after replacing, onResume() is never called on Fragment B, though I can interact with it. Also, onDestroyView is never called on Fragment B. val transform = MaterialContainerTransform() …
1
vote
1 answer

Viewpager Fragment 1 onCreateView is not always being called

When I swipe to or select Fragment1 (Fragment Numbers are 0-3) from its adjacent Fragments(0 , 2) in viewPager its onCreateView, or onCreate function is not being called. But when I swipe back from Fragment3 or select Fragment1 when Fragment3 is…
1
vote
1 answer

How to detect fragment is idle for some time in android

I want to check that no one has interacted with fragment UI for some time and on the bases of that I want to call a Function/Method inside fragment. Android Studio
1
vote
2 answers

Explanation needed for - Blank Fragment Java code in Android Studio

I'm working with Bottom Navigation bar in Android Studio After creating menu and other MainActivity.java codes, Created fragments for my menu items. So I Choose the BlankFragment templates in Android Studio. its creates both .java and .xml file…
1
vote
1 answer

Does adding a new fragment to the backstack pause the current fragment?

I am currently adding a new fragment to the backstack (On top of the current fragment): val fragmentTransaction = fragmentManager?.beginTransaction() fragmentTransaction?.add(R.id.cl_my_profile_edit, newFragment)?.addToBackStack(null) …