Here is the mainfest :
<activity android:name=".MainActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Main2Activity"
android:screenOrientation="portrait">
</activity>
We have two activities, orientation of both is restricted to Portrait as specified in Manifest. MainActivity
is launching Main2Activity
, onBackPressed()
of Main2Activity
is overridden and showing a Toast
code is below:
@Override
public void onBackPressed() {
Toast.makeText(Main2Activity.this,"This is from Second",Toast.LENGTH_SHORT).show();
super.onBackPressed();
}
Problem Statement:
1. Keep the phone in Landscape
2. Launch the App
3. MainActivity
gets created in Portrait (no issue till here)
4. Launch Main2Activity
from MainActivity
, There is a button that do that
5. Main2Activity
open up in portrait (no issue till here)
6. Press hardware back button, Main2Activity
gets dissappered
7. MainActivity
shows up in landscape with Toast then it automatically changes to Portrait.
8. Device was on landscape during all these steps
9. Tried changing context to Application context but no luck
10. Removed the Toast and everything works as expected
Why this behaviour in Point 7?