7

I am creating an application wherein I am having a lock screen which comes up whenever the application moves to the background.

I want that on pressing the recent apps, the screenshot of my application(or that activity) be avoided. One way is to use the "Secure Flag". But that would as well avoid taking screenshots in application which I don't want.

Hence, one way I was thinking is onStop() or onPause() of the activity(moving into the background), I start the lock screen activity which would ultimately result into the snapshot of the lock screen. But that does not seem to work.

Is there any other way for the same?

MainActivity extends LockActivity.

LockActivity has the lock code

Thanks in advance.

android developer
  • 1,253
  • 2
  • 13
  • 43

1 Answers1

0

Rather than starting a new activity, you can hide the current content of the activity and display another content which might be hidden when the acivity is active.

For example, in your XML layout file, add an "ImageView" with visibility=View.GONE. When the activity calls the onPause() method, you can make the visibility=View.VISIBILE. Make sure the imageView is on top of the rest of the elements in the layout.

I haven't tested this but it might work.

swbandit
  • 1,986
  • 1
  • 26
  • 37
  • Your approach does make sense. But If I have n number of activities, then? – android developer Jul 30 '14 at 15:04
  • You could do the same programmatically. And if you want to reuse the code, you could create your own SecureActivity class that extends the regular Activity and include the code for hiding the contents there. Then all the activities would extends the SecureActivity class and your code would be maintained in one place. But see if this approach works in the first place. Then you can worry about code re-usability and maintenance. – swbandit Jul 30 '14 at 15:11
  • Thanks @Mike T. Will surely try this approach and get back. – android developer Jul 30 '14 at 15:24
  • 1
    I tried your approach of creating a view dynamically over the existing view. I call this view in the onPause(). Unfortunately its too late for the system to capture the screenshot. – android developer Jul 31 '14 at 09:24
  • I tried this approach, which I thought makes sense and should work. But it doesn't ...which means that the screenshot is getting captured before on pause. – Avijeet Nov 23 '16 at 10:20