Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide last activity view in android recent list? Using a locker screen implementation

I am using an implementation of locker screen which locks (is displayed on top) the current activity when it is idle for X seconds. However the view for the locker activity is not displayed in the preview image after clicking the Home and Recent buttons.

enter image description here

How could I force to make my app's view blank or display my locker view in the recent list? I could set my activity visible to gone, but is there any other solution?

like image 522
deadfish Avatar asked Feb 17 '23 14:02

deadfish


1 Answers

Try FLAG_SECURE:

public class FlagSecureTestActivity extends Activity {
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE,
                         WindowManager.LayoutParams.FLAG_SECURE);

    setContentView(R.layout.main);
  }
}

It will automatically display a grey background when Recents button is pressed.

A possible side-effect would be that you cant take the screenshot of the activity you are defining this way.

like image 140
Kumar Adarsh Avatar answered May 06 '23 23:05

Kumar Adarsh