Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug fix: fragments are duplicated and overlaped #48

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

bug fix: fragments are duplicated and overlaped #48

wants to merge 1 commit into from

Conversation

zdsfwy
Copy link

@zdsfwy zdsfwy commented Aug 28, 2016

Hi, professor.
In FragmentProgrammaticLayout, the main Activity would add fragment whenever onCreate is invoked. As a result, when onCreate is invoked by configuration changing, duplicated fragments would be added and overlapped.
Here are the screenshots.Before configuration change:
device-2016-08-28-223937
After configuration change(since new fragment is overlapped with old fragment, multiple items in the list appear to be selected):
device-2016-08-28-224056

@JoelEspinal
Copy link

Hi, Good Afternoon.
My name is Joel.

I don't understanding your fix completely.

If this was your solution I appreciate some lite explanation about it. ;)

I think the Issue is about Fragment lifecycle.
maybe you can find a more appropriate solution on that way.

Thanks for your time,

Joel Espinal (JoelEspinal)
Developer

here a part snipped code:

if(savedInstanceState != null) {

  •      return;
    
  •  }
    

@zdsfwy
Copy link
Author

zdsfwy commented Aug 29, 2016

Hi, Joel. Thank you for reply.

Sorry for leading to confusing. Let me explain if(savedInstanceState != null) { return; } .

When configuration(such as orientation) changes, android system would restart the app. Before restart, it would save certain information into savedInstanceState, and pass it as parameter to onCreate method. If savedInstanceState is not null, it means this is not a newly created app, but restarted app. Since in this example FragmentProgrammaticLayout , fragments are only needed to be added once when the app is newly created, they don't need to be added again when restarted. So, it should just directly return.

Here is the link from google android site, where it uses exactly the same technique.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants