0

I need to keep my app in the recents menu, but blank the screen or "screenshot" when the app goes in the background. I've tried using

getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);

in the Activity onCreate() method before calling setContentView() but this doesn't work. The recents screen still always shows the app's content from the last time it was placed in the background in the recents menu.

Has something changed on Android? I scoured SO and Google on this subject and every article I found (most recently from 2018) devs seemed to portray that this solved their problem. I'd be happy to provide more information as needed.

whitaay
  • 493
  • 1
  • 6
  • 18

1 Answers1

0

How about setting the visibility to the parent xml element to GONE and VISIBLE during the appropriate lifecycle events? example:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal"
    android:id="@+id/layout_to_hide" >

    <

     // xml content

    />

</LinearLayout>

In code:

LinearLayout linearLayout = findViewById(R.id.layout_to_hide);

@Override
public void onResume() {
    super.onResume();
    linearLayout.setVisibility(VISIBLE);
}

@Override
public void onPause() {
    super.onPause();
    linearLayout.setVisibility(GONE);
}
JakeB
  • 2,043
  • 3
  • 12
  • 19
  • I tried this. Evidently the screenshot that shows up in the recents screen is taken before onPause() gets called (which makes little sense to me) so this won't work. – whitaay Sep 10 '19 at 20:51
  • Found this answer, might be worth giving it a go? https://stackoverflow.com/a/52976001/5644761 – JakeB Sep 11 '19 at 10:13