Screen Blinks when Screen Orientation Changes in Android?

Maybe some fade or something also I see how this can be an issue because when you are starting a new activity there is the small bit of time untill the view is inflated in setContentView, so probably you see the screen going black until that step is complete. Maybe use traceview to see where it takes up the time and maybe optimize the onCreate->onDestroy methods a bit Creating an activity is an expensive process. Maybe if this really feels annoying to you, go with a view flipper and move all the code that you can into seperate views inflating them from xml(maybe if they arent too heavy you can load them both in onCreate and probably reuse a lot of the variables declared for the portrait view and the landscape.

You will leave the dependant code in the activity and move the unique functionalities for each view into the view classes this is just a tought. I have done this with a coverflow and a gridView containing image thumbs and it turned out great. Switching views was really fast and it had a really great low memory consumption, mainly because data was shared between the views EDIT So you want to do something like this letting the views restart or retainConfigurationState (in the android docs it says that way orientation change is handled a bit faster).

Here is the code for handling orientation change with an activity group: I have 2 activities A and B which can be any type (TAbActivity etc... ) and I have 1 main activity called OrientationChangeActivity: public class OrientationChangeActivity extends ActivityGroup { private ArrayList mIdList; @Override public void onCreate(Bundle savedInstanceState) { super. OnCreate(savedInstanceState); setContentView(R.layout. Main); mIdList = new ArrayList(); if (getResources().

GetConfiguration(). Orientation == Configuration. ORIENTATION_PORTRAIT) { startChildActivity("ActivityA", new Intent(this, ActivityA.

Class)); } else if (getResources(). GetConfiguration(). Orientation == Configuration.

ORIENTATION_LANDSCAPE) { startChildActivity("ActivityB", new Intent(this, ActivityB. Class)); } } This is using the link posted in my comment. I have Activity A set to orientation portrait and Activity B as Landscape.

I am letting OrientationChangeActivity restart itself (doesn't contain a configChage declaration in the manifest) thus calling onCreate again and switching the activity You can also look at the code: Override public void finishFromChild(Activity child) { LocalActivityManager manager = getLocalActivityManager(); int index = mIdList.size() - 1; if (index Get(index), true); mIdList. Remove(index); index--; String lastId = mIdList. Get(index); Intent lastIntent = manager.

GetActivity(lastId).getIntent(); Window newWindow = manager. StartActivity(lastId, lastIntent); setContentView(newWindow.getDecorView()); } which tells you how to create an activity inside the activityGroup and set it to the view. You can use this code to load both the activites on create here and set them according to orientation change as the content View.(meaning you need to add configChage=orientation).

Maybe some fade or something. Also I see how this can be an issue because when you are starting a new activity there is the small bit of time untill the view is inflated in setContentView, so probably you see the screen going black until that step is complete. Maybe use traceview to see where it takes up the time and maybe optimize the onCreate->onDestroy methods a bit.

Creating an activity is an expensive process. Maybe if this really feels annoying to you, go with a view flipper and move all the code that you can into seperate views inflating them from xml(maybe if they arent too heavy you can load them both in onCreate and probably reuse a lot of the variables declared for the portrait view and the landscape. You will leave the dependant code in the activity and move the unique functionalities for each view into the view classes.

This is just a tought. I have done this with a coverflow and a gridView containing image thumbs and it turned out great. Switching views was really fast and it had a really great low memory consumption, mainly because data was shared between the views.

EDIT So you want to do something like this letting the views restart or retainConfigurationState (in the android docs it says that way orientation change is handled a bit faster). Here is the code for handling orientation change with an activity group: I have 2 activities A and B which can be any type (TAbActivity etc... ) and I have 1 main activity called OrientationChangeActivity: public class OrientationChangeActivity extends ActivityGroup { private ArrayList mIdList; @Override public void onCreate(Bundle savedInstanceState) { super. OnCreate(savedInstanceState); setContentView(R.layout.

Main); mIdList = new ArrayList(); if (getResources(). GetConfiguration(). Orientation == Configuration.

ORIENTATION_PORTRAIT) { startChildActivity("ActivityA", new Intent(this, ActivityA. Class)); } else if (getResources(). GetConfiguration().

Orientation == Configuration. ORIENTATION_LANDSCAPE) { startChildActivity("ActivityB", new Intent(this, ActivityB. Class)); } } ............ This is using the link posted in my comment.

I have Activity A set to orientation portrait and Activity B as Landscape. I am letting OrientationChangeActivity restart itself (doesn't contain a configChage declaration in the manifest) thus calling onCreate again and switching the activity. You can also look at the code: @Override public void finishFromChild(Activity child) { LocalActivityManager manager = getLocalActivityManager(); int index = mIdList.size() - 1; if (index Remove(index); index--; String lastId = mIdList.

Get(index); Intent lastIntent = manager. GetActivity(lastId).getIntent(); Window newWindow = manager. StartActivity(lastId, lastIntent); setContentView(newWindow.getDecorView()); } which tells you how to create an activity inside the activityGroup and set it to the view.

You can use this code to load both the activites on create here and set them according to orientation change as the content View.(meaning you need to add configChage=orientation).

I have the Activity A as a TabActivity Content. The Activity B is belongs to Activity Class. In this case, How can I work with the views.

If there is no Tabhost then TabActivity should throw the Fatel Exception. Any Idea on this? – SACPK Jul 15 at 6:52 I don't really understand what you are saying.

You have one TabActivity (A) that is in portrait and that one is replaced with an Activity (B) when orientation is changed? – DArkO Jul 15 at 8:01 Yes Exactly... Do you have any idea on this? – SACPK Jul 15 at 9:39 Well I don't see how you can easily make the changes to using a single activity and a view.

Usually this is handled with a ActivityGroup instead of having config changes in both your activities. See this: ericharlow.blogspot. Com/2010/09/….

I believe this is the best way to handle what you need and not modify your current implementations. Just handle the orientation changes in the ActivityGroup and load accordingly. (i think you can load both of your activities on startup and just set the one you want as a view - according to orientation) – DArkO Jul 15 at 9:52 Have config changes there and just change the decor view to the proper activity.

I think you can even wait until the next screen is loaded and then switch it (eliminating the black screen wait until setContentView() and tab initialization is finished in your child activities). The example in the link is for having multiple activities in a tab but can be easily reworked for what you need. The principle is the same.

– DArkO Jul 15 at 9:54.

(such as screen orientation, keyboard availability, and language). Activity (onDestroy() is called, followed by onCreate()). Alternative resources that match the new device configuration.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions