3

I have one activity which has view-pager with 3 fragments, activity will always in portrait mode but if the user is viewing 3rd page(Fragment) and rotates the screen to landscape app will launch another activity in landscape mode and shows detailed data inside table layout, and again when user rotates device from landscape to portrait that activity finishes and previous activity comes to foreground in portrait mode.

But when I rotate the device from landscape to portrait mode app show black screen for a while before portrait activity(which contains view-pager) comes to the foreground.

Can anyone knows how to avoid this black screen on switching between activities?

I really need to fix this thing.

Thanks in advance.

Mohit Charadva
  • 2,555
  • 1
  • 22
  • 30

1 Answers1

2

By the

Blockquote [...] and previous activity comes to foreground in portrait mode.

Seems you create new activities on rotation (not recreating), so you should see this part of code.

On every rotation, the activity is recreated (delete and create again), so could have some delay between recreation, while a black screen will appear. Some trick to avoid this android cycle is to set myFragment.setRetainInstance(true)

This will avoid the recreation of your fragments on rotation, this make faster the change orientation, but is not usefull in all apps, give it a try.

Hope this helps.

Sulfkain
  • 5,082
  • 1
  • 20
  • 38