I found that when we change the orientation of current activity by screen rotation, the previous activity will be recreated in background.
What I’m trying to say is, for example:
I had set the screen orientation for both activity in the manifest file
<activity android:screenOrientation="portrait" android:name="package.PotraitActivity"></activity>
<activity android:screenOrientation="landscape" android:name="package.MyActivity"></activity>
In PotraitActivity.java,
Button mybutton = (Button)findViewById(R.id.mybutton);
mybutton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view)
{ Intent intent = new Intent(this,MyActivity.class);
startActivity(intent);
}
});
When clicked on myButton, LandscapeActivity was been started. But at the same time OnCreate() method in PotraitActivity was called as well.
I found the same thing happened when:
- the screen orientation for both activities is different or
- Screen rotation is enabled for MyActivity (screenOrientation=”user”). OnCreate() method in PotraitActivity is called every time we rotated MyActivity.
Anyone has idea about this?
Set
android:configChanges="orientation"to your package.PotraitActivity activity in manifest. Setting this will ignore the default screen orientation implementation and will give you the control to override it manually.