Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide a view before onStop?

Tags:

android

When user press home button onStop() method is called and system takes screenshot which can be seen among open applications when user press and hold home button(on android phones). My question is how to prevent sensitive data to be visible to anybody who can take a phone and press and hold home button? Imagine, application(activity) presents a preview of secret document and user press home button(maybe somebody just approached to the user and he doesn't want to anybody see his secret document). However, anybody who takes a phone after that can press and hold home button and see some sensitive data.

I tried to hide view onPause and/or onStop but that doesn't work. So, how to remove current visible view before system takes screenshot after onStop?

Thanks.

like image 837
xezo Avatar asked Jul 12 '26 07:07

xezo


1 Answers

My question is how to prevent sensitive data to be visible to anybody who can take a phone and press and hold home button?

Quoting myself:

However, for the user’s benefit, there may be reasons to block screenshots from certain of your activities. To do that, use FLAG_SECURE:

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

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

    setContentView(R.layout.main);
  }
}
like image 76
CommonsWare Avatar answered Jul 14 '26 23:07

CommonsWare



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!