Reputation: 91175
I have two Activities A
and B
. I have declared the screenOrientation
for A
as portrait and for B
as landscape in the manifest file. I am starting the Activity from A
to B
. when I am starting the Activity A
as well as finishing the Activity B
, My Screen is blinking. I have set that configChanges
for both activities as orientation
.
this is the Manifest code snippet:
<application
<activity android:name=".A"
android:label="@string/app_name" android:theme="@style/MyTheme"
android:screenOrientation="portrait" android:windowSoftInputMode="stateAlwaysHidden|adjustUnspecified"
android:configChanges="orientation" />
<activity android:name=".B"
android:label="@string/app_name" android:theme="@style/MyTheme"
android:screenOrientation="landscape" android:windowSoftInputMode="stateAlwaysHidden|adjustUnspecified"
android:configChanges="orientation" />
</application>
Is there any idea to resolve this issue???
Thanks in Advance.
Upvotes: 2
Views: 2564
Reputation: 16110
First did you try to overridePendingAnimation when you are starting the intent between screens? 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<String> mIdList;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mIdList = new ArrayList<String>();
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 < 1) {
finish();
return;
}
manager.destroyActivity(mIdList.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).
Upvotes: 1