I have one big and long question
I have one activity with 4 fragments using viewPager.
the first fragment also has 4 fragments using viewPager
the second fragment has 6 fragments using general fragment way (replace or add on framelayout)
Here are my question and problem
For example, I am in the first tab and in the second fragments, then hit homebutton and then bring my app upfront. after that suddenly all functionalities are not working. the back button is not working. the button in the fragment is not working. (error log said the fragment is not attatched)
it happens only on pixel3.
I have 5 different android phones but working fine on those phones.
I thought it could be the memory issue, so I turned on "profiler" from Android Studio, and I saw the weird thing. only pixel3 when I pressed the home button the activity is destroyed. I tested all other phones with "Profiler" the activity's state is saved not destroyed.
Does anyone have the idea of why it happened and fixed the problem?
Are the embedded fragments problem? or is it OS10 problem?
I found the issue. there is one option in developer mode named "Don't keep activities". that was on, that is why my app is working differently on pixel3.
Related
I have the following issue and I'm no quite sure whether it is a bug or misunderstanding by me.
I have a single activity, Fragment A (attached to activity's onCreate Method) and Fragment B (not attached to activity during its creation). On button click, Fragment A is replaced with Fragment B with transition. So far so good.
On Fragment B there is button which invokes fragmentManager.popBackStackImmediate(). If I press this button and turn the screen off at the same time (during fragment transition) then, when the screen is back on, the two fragments are visible (fragment B should have been destroyed, but it is not).
This problem starts with support lib 27.1.0+. Prior to that, the fragments were replaced correctly during Back stack navigation. Have in mind that I'm using fragments from support library.
I read behavior changes but I could not manage to link some of it to my issue.
Does anybody knows some work around or has more information about it?
Thanks in advance!
UPDATE:
Problem exists only on devices up to Android 6. On Android 7+ everything is alright.
fragmentManager.beginTrasaction().replace().addToBackStack() - do it for FragmentA in onCreate and do it on click for FragmentB. And try popBackStack(). I think you forgot addToBackStack FragmentA.
I'm wondering if this is a 'no no' in the Android community.
My app just has a MainActivity and uses a ViewPager and TabLayout to navigate across the fragments in the app.
The only problem I see is if the user presses the back button, it will exit the app and the app will not stay active like it would by pressing the home button.
Your thoughts?
Nice question bro,
Few months back I was thinking in sameway.
You are 100% right, you can do it without any trouble, it only depend on your project and what do you want to achieve.
You could control your fragments from a single activity, beacause all fragments are independent of each other.
The limitation is :
One fragment should never talk directly to another fragment, you have to go through the parent activity
Only some imp points are:
You need to learn all details about fragment.
You have to manage the order of the fragments.
It add lbit complexity in code
One Activity and all other Fragments
I just want to ask why my app crashes with the following conditions.
I am working with fragments with only one activity. In my fragment, say FragmentA, I create views dynamically (inflating them). They work fine. But when I press home button, and go to the app again, I expect that FragmentA will be displayed but unfortunately, it throws NullPointer.
There is no errors in my android phone[GingerBread] but on my Tab, this error happens. Any help will be higly appreciated. Thanks.
You are not providing enough information to reliably answer this question, but the difference your're seeing is probably related to different behaviour of the garbage collector on the two different devices. As they are running on two different devices they will also behave differently.
The null-pointer you are seeing I would guess stems from wrongful use of member variables in your fragment.
When you go to the home screen and back your fragment will (or more accurately CAN) be recreated. Read: destroyed and re-instantiated using the argument-less constructor.
So make sure your fragment(s) are properly saving any needed state in onSaveInstanceState and restore this information in OnCreate/OnCreateView or whatever you're using.
I have a sherlock activity(A) that contains a fragment(B) which again contains a tab and FragmentViewPager(C) which contains a Fragment (D).
I have a weird issue here.
Initially everything shows up fine.
If I close the app by pressing the home button, then come back immediately to the app, then everything is fine (A containing B containing C containing D)
However, if I close the app by pressing the home button, then work on other apps for a long time, then come back to my app, then I see A containing B containing C containing an empty screen.
Here are two questions.
1. Why doesn't the fragment D show up?
2. It seems like something is wrong with onResume() or something in D? Or is it related to process issue? Lifecycle? How can I fix that?
3. In order to recreate the issue, I have to close the app, then spend a lot of time playing other apps. Is there a way to recreate this issue quickly without having to waste time?
Thanks a lot...
I have 2 projects with tabbars. In each project activities are binded to tabbars. However, in the first one activities are created only for the first time I switch to certain tab (I suppose this behaviour is normal). In the second one onCreate is called each time I switch to a tab regardless the fact whether instance of this activity was created before.
I cant understand why 2 apps (2 projects = 2 apps) behave in such a different way. In neither project I tried to archieve any behaviour - it happened by itself. Can anyone explain me possible reasons of different behaviours?
Without seeing your code we can only guess.
Perhaps you are calling finish() on your activities in the one app and not in the other.