Skip to content Skip to sidebar Skip to footer

Fragment Called Twice

I'm trying to start a fragment from an activity, but everytime I start the app, the fragment is started twice. This is only happening when I run the app on a tablet device. Does an

Solution 1:

When you're starting your Activity you're calling:

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

When calling this method, your Activity is possibly restarted, if the tablet is in portrait mode when the app starts up. This is stated in the documentation.

When you're Activity is restarted, onCreate is called once again and your Fragment is created once again.

On a side-note: It's not good practice to force your app into a specific orientation.

Post a Comment for "Fragment Called Twice"