Search code examples
androidandroid-activityorientationandroid-orientationorientation-changes

Handle orientation on previous activity after finish() of topactivity


There are two activities say

  • Activity_Previous (ListActivity with android:empty textview)
  • Activity_Current(to delete list items and return to Activity_Previous ).

Configuration changes for Activity_Previous is handled in onConfigurationChanged() with setcontentview.

The problem is : In landscape mode, user moves from Activity_Previous to Activity_Current. Now If the user deletes all list items then finish() of Activity_Current is called, then the android:empty textview in the layout of Activity_Previous is not according to the orientation (i.e. portrait text in landscape mode. But then after rotation the problem is fixed. I think the problem can be with the onConfigurationChanged() method not being called for the Activity_Previous after the finish() of Activity_Current.

Please suggest if the problem can be fixed in the existing structure.

Here are the logs :

07-11 11:42:38.469 3438-3438/? D/IActivity1: onCreate

07-11 11:42:38.579 3438-3438/? D/IActivity1: onStart

07-11 11:42:38.579 3438-3438/? D/IActivity1: onResume

07-11 11:42:45.189 3438-3438/? D/IActivity1: onConfigurationChanged

07-11 11:42:50.229 3438-3438/? D/IActivity2: onCreate

07-11 11:42:50.319 3438-3438/? D/IActivity2: onStart

07-11 11:42:50.329 3438-3438/? D/IActivity2: onResume

07-11 11:42:50.779 3438-3438/? D/IActivity1: onStop

07-11 11:42:59.929 3438-3438/? D/IActivity2: onPause

07-11 11:42:59.949 3438-3438/? D/IActivity1: onStart

07-11 11:42:59.949 3438-3438/? D/IActivity1: onResume

07-11 11:43:00.269 3438-3438/? D/IActivity2: onDestroy

(Here Activity1 is Activity_Previous)

Thanks!


Solution

  • I have added following in the onResume of Activity_Previous :

    Configuration c = getApplicationContext().getResources().getConfiguration();

    onconfigurationChanged(c);