MainActivity launches FullActivity (which has no status bar). When the user presses the back button from the FullActivity, FullActivity is dismissed and MainActivity will be shown again.
The problem is that when the MainActivity gets shown again, it seems as if the MainActivity is transitioning from fullscreen to normal screen. The whole UI moves down by the height of the status bar. This looks annoying. I never meant the MainActivity to be fullscreen. Why is this happening, and how can I prevent this?
In short, I want the MainActivity to stay normal and never go fullscreen.
I tried adding the following code to the MainActivity's onCreate, according to an answer to a similar question, but it did not work
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
I tested this on Nexus 7 (2013), Android 6.0.1.
MainActivity.java
public class MainActivity extends AppCompatActivity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button full = (Button)findViewById(R.id.full);
full.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
Intent i = new Intent(MainActivity.this, FullActivity.class);
startActivity(i);
}
});
}
}
FullActivity.java
public class FullActivity extends AppCompatActivity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
int flags = WindowManager.LayoutParams.FLAG_FULLSCREEN;
getWindow().setFlags(flags, flags);
TextView hello = new TextView(this);
hello.setText("Press the back button to dismiss me.");
setContentView(hello);
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.example.me.test2"
xmlns:android="http://schemas.android.com/apk/res/android">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:theme="@style/Theme.AppCompat.NoActionBar">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".FullActivity"/>
</application>
</manifest>
activity_main.xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<Button
android:text="Show full screen activity"
android:id="@+id/full"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<ListView
android:entries="@array/list_items"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="1dp"></ListView>
</LinearLayout>
strings.xml
<resources>
<string name="app_name">Test2</string>
<string-array name="list_items">
<item>Homer</item>
<item>Marge</item>
<item>Bart</item>
<item>Lisa</item>
<item>Maggie</item>
<item>Santa\'s Little Helper</item>
<item>Snowball II</item>
<item>Flanders</item>
<item>Moe</item>
</string-array>
</resources>
