fragment-lifecycle

Kotlin - fragment lifecycle navigation issues; why does child fragment become current destination?

匆匆过客 提交于 2021-01-29 09:17:25
问题 Kotlin/Android novice. Please bear with me. My app has the following navigation scheme: BottomNavigationView with navigationController where fragment One, Two and Three are "top destinations", from which I look to navigate further down in the navigation hierarchy. I implemented the scheme following this video tutorial. MY ISSUE Fragment Three is a QR-code scanner. Upon successful scan I aim to navigate to fragment X. However, when I reach the point of navigation, fragment X has become

Fragment lifecycle events in LifeCycleAware Fragment

て烟熏妆下的殇ゞ 提交于 2020-12-08 05:34:12
问题 I have a lifecycle aware fragment and a LifecycleObserver class public class MyFragment extends Fragment { @Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); new MyObserver(this); } @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) { return inflater.inflate(R.layout.activity_main, container, false); } } Following is my Observer class where it logs all the

How does fragment's lifecycle works inside viewpager? Why onStop is not called on navigation change?

被刻印的时光 ゝ 提交于 2020-04-16 05:42:38
问题 I'm using ViewPager 2 from AndroidX with 4 instances of the same fragment. My question is pretty straight forward. When I'm navigating to some another fragment(using navigation drawer or even something else). OnStop() , OnDestroy(), OnDettach() of the fragments inside the viewpager does not gets triggered. So why is that? And If I want to remove the listeners I've started already, in one of these methods, how can I do that? For example, I'm using GreenRobot's EventBus. And I'm registering the

How does fragment's lifecycle works inside viewpager? Why onStop is not called on navigation change?

只谈情不闲聊 提交于 2020-04-16 05:42:24
问题 I'm using ViewPager 2 from AndroidX with 4 instances of the same fragment. My question is pretty straight forward. When I'm navigating to some another fragment(using navigation drawer or even something else). OnStop() , OnDestroy(), OnDettach() of the fragments inside the viewpager does not gets triggered. So why is that? And If I want to remove the listeners I've started already, in one of these methods, how can I do that? For example, I'm using GreenRobot's EventBus. And I'm registering the

injecting viewmodel with navigation-graph scope: NavController is not available before onCreate()

梦想的初衷 提交于 2020-02-15 00:22:42
问题 I'm using a navigation-component in my application and also using shared ViewModel between multiple fragments that are in the same graph. Now I want to instantiate the ViewModel with this graph scope with this. As you know, in fragments we should inject objects ( ViewModel,..etc ) in onAttach: but when I want to do this (injecting ViewModel with a graph scope in onAttach ), this error occurs: IllegalStateException: NavController is not available before onCreate() Do you how can I do this? 回答1

injecting viewmodel with navigation-graph scope: NavController is not available before onCreate()

此生再无相见时 提交于 2020-02-15 00:21:08
问题 I'm using a navigation-component in my application and also using shared ViewModel between multiple fragments that are in the same graph. Now I want to instantiate the ViewModel with this graph scope with this. As you know, in fragments we should inject objects ( ViewModel,..etc ) in onAttach: but when I want to do this (injecting ViewModel with a graph scope in onAttach ), this error occurs: IllegalStateException: NavController is not available before onCreate() Do you how can I do this? 回答1

injecting viewmodel with navigation-graph scope: NavController is not available before onCreate()

老子叫甜甜 提交于 2020-02-15 00:20:10
问题 I'm using a navigation-component in my application and also using shared ViewModel between multiple fragments that are in the same graph. Now I want to instantiate the ViewModel with this graph scope with this. As you know, in fragments we should inject objects ( ViewModel,..etc ) in onAttach: but when I want to do this (injecting ViewModel with a graph scope in onAttach ), this error occurs: IllegalStateException: NavController is not available before onCreate() Do you how can I do this? 回答1

When will onResume() be called without onStart() being called first (Fragment Lifecycle)

蹲街弑〆低调 提交于 2020-01-04 05:20:51
问题 onStart() is when the Fragment becomes visible, onResume() is when the Fragment becomes interactive. So when will the onResume() -> onPause() -> onResume() cycle execute without executing the encompassing onStart() -> onStop() cycle? In terms of fragment transitions, a replace will destroy the starting fragment, calling its onPause() -> onStop() as well as other destroy related life-cycle methods. If the transition is replace but add the starting fragment to **backStack** , it will still call

Stop handler after the fragment has been destroyed

試著忘記壹切 提交于 2020-01-01 08:30:15
问题 I have a Fragment which sets up a ListView and creates a Handler to update the Listview periodically. However, it looks like the Handler still runs after the Fragment has been destroyed. The following is the code. @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { //boilerplate code final Handler handler = new Handler(); handler.post(new Runnable() { @Override public void run() { assignAdapter(); handler.postDelayed(this, 15000); } })

RecyclerView doesn't load data on first launch after Permission Check inside fragment

China☆狼群 提交于 2019-12-24 10:15:34
问题 RecyclerView adapter doesn't load data on first launch after Permission check. I have to re-tap the tab to get the data. I have already visited/tried these links - -- RecyclerView doesn't load data in first launch using FirebaseRecyclerAdapter -- RecyclerView doesn't load items on first start of activity -- recyclerview not loading adapter values in a fragment But nothing works yet. Tried to set global adapter, So I can call notifyDataSetChanged() from onResume() . Still It didn't worked.