asdheeraj / BottomNavigation

This project helps in understanding how to save the Fragment state by using the Bottom Navigation View
14 stars 8 forks source link

Overlapping the UI #1

Open bamakant opened 4 years ago

bamakant commented 4 years ago

After doing some changes in code while I am doing "Apply changes" in Android studio the UI screen is being overlapped with others. For example: Suppose you are currently in "AfterAcademy" Fragment and did some UI changes and did "Apply changes" which is preferable for fast reflection in only changed UI code but not the whole activity then the other UIs like "Mindorks" fragment UI is being overlapped with the current one and then it's just messed up.

I am not getting it how to fix it so I just let you know if you have faced this issue or come through ever.

Let me know what to do to resolve it.

asdheeraj commented 4 years ago

added 'android:background="@android:color/white"' attribute for all the fragment layouts. Not having a specific background might be resulting in the overlap. I've committed the code to the master branch. U can take the latest master branch and check. If you feel fine, you can close the issue.

bamakant commented 4 years ago

Have you tested this solution? Because as Its creating another issue like when I am doing apply changes then it showing the starting fragment(mindorksFragment) regardless of the selected fragment in bottom navigation bar. And then while navigating through these fragments all other fragments working fine except the fragment which was selected before doing the apply changes run.

asdheeraj commented 4 years ago

Yup. It is because if you see the MainActivity, MindOrks fragment is the active fragment that we are initializing and showing it, hiding the rest of the fragments(in oncreate method). So when we click apply changes the oncreate is called again (since the current activity is recreated) and the current selection fragment is replaced with the mindorks fragment. You can refer this blog for info on ApplyChanges in Android Studio: https://medium.com/androiddevelopers/android-studio-project-marble-apply-changes-e3048662e8cd

Simply putting it, The oncreate is called since the activity is recreated if apply changes is clicked and the UI displays this accordingly.

You can also check this by adding a Log statement in the oncreate and then clicking on apply changes. (Ensure that you click. on apply code changes and then apply changes) or rerun the application first and then click on apply changes so that the code is present in the emulator/device

bamakant commented 4 years ago

Exactly, how it is working. But this issue I am talking about is not only creating during apply changes feature but in production too and that's the reason I am asking you about this that how can I solve this.

After using for some time I just minimized(by pressing the home button) the application on ProfileFragment then after some time may be 10-20min or later on when I am re-opening the application it's overlapping the UI and that's where I am afraid of using this approch.

So can you just look into it and suggest some solution for this.

asdheeraj commented 4 years ago

Sure.. let me try the scenario u have mentioned. Just give me some time. Thanks for bringing this up :)

asdheeraj commented 4 years ago

I've tried many times to recreate this issue by minimizing and relaunching but I was not able to find the overlap. Yes, if we click on "apply changes" the first fragment("mindorks fragment in this case") is added to the selected tab. But this is because of activity recreation. And this can be an apply changes bug from Android Studio

But in production-level code, since the app is run on the mobile, I was unable to recreate the issue uve mentioned.

Adding a background to the fragment is a hack, and I don't want to do hotfixes currently, hence reverting the change and committing the code.

bamakant commented 4 years ago

Okay NP, When I face the issue again then I will share the screenshot with you. Till then let's not close the issue.

bamakant commented 4 years ago

Hey, @asdheeraj I may get it why you are not able to create that issue. Actually this issue is created if and only if the app has not been closed for a while like around 20-30 min but also you have not used it in this period. If you have kept your mobile in battery saving mode then it might be closing the app and preventing it to run in the background and that's why it restarting the app again while you open it which recreating the main fragment and not creating the issue.

So I suggest start the app and keep it in AfterAcademy fragment and just minimize it, leave it for some time as I said, no need to keep looking into it, just do your work and then open the app from the recent apps menu(although it's not necessary but it may help) then you will see in bottom navigation menu AfterAcadem is selected but the UI will be of MindOrks fragment and that's where the Overlapping of UI is happening.

In production, this usually happens like during using the app we used to keep our app minimized to do our work then after some time when we start our app since we haven't closed the app so it try to start from where we left it and that's where the issue is creating in this technique of saving the bottom navigation state.