How to hide last activity view in android recent l

2019-06-24 19:41发布

问题:

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.

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?

回答1:

Try the attribute, android:noHistory="true" for the activity tag in the manifest file.



回答2:

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.



回答3:

The recents app gets something like a "screenshot" when the app goes to background, so before go to background you can fill your activity with a black LinearLayout and onResume check if this LinearLayout is showing and hide. Maybe there are better solutions but this may works.