4

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?

Community
  • 1
  • 1
deadfish
  • 11,996
  • 12
  • 87
  • 136
  • 2
    Best solution might be found here http://stackoverflow.com/questions/9822076/how-do-i-prevent-android-taking-a-screenshot-when-my-app-goes-to-the-background – deadfish Feb 11 '13 at 13:37

3 Answers3

7

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.

Kumar Adarsh
  • 71
  • 1
  • 2
2

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

Gopinath
  • 12,981
  • 6
  • 36
  • 50
  • It destroys trace unfortunately. I want just see blank preview for my app. Think in this way: you pasted in plain text password on your activity and you don’t want see this text in preview list last opened apps. Besides, destroying trace sounds like hack, not solution. – deadfish Feb 08 '13 at 11:09
  • Override onStop() method and just try resetting the content view of your activity to some blank xml file before you call super.onStop(). Probably, Android framework will make a screenshot of your app for showing in the recent apps when activity.onStop() is called! – Gopinath Feb 08 '13 at 11:20
  • @deadfish Did you got any proper solution? – Alvin Varghese Jun 20 '17 at 09:39
  • @nope, however native Google Alarm Clock app might give You a tip. Look how it behaves when alarm runs. – deadfish Jun 20 '17 at 11:38
0

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.

PaNaVTEC
  • 2,505
  • 1
  • 23
  • 36