I want to hide my views when my app is backgrounded. For e.g. I want to hide this "Live Debug Mode" textview when my app is backgrounded.
Asked
Active
Viewed 1,913 times
5
-
explain more please – Mehdi Akbarian Rastaghi Jul 15 '16 at 20:05
-
Android doesn't have the concept of "minimizing", just putting to the background, so I don't understand... And *where* does it show the views? – OneCricketeer Jul 15 '16 at 20:15
-
if your app is "minimized" how can you see it? – tyczj Jul 15 '16 at 20:17
-
What do you mean by minimizing an app? Please attach a picture of your minimized app to get your question more clear. – Akeshwar Jha Jul 15 '16 at 20:20
-
@cricket_007, I do not believe this is a duplicate question. This question is specifically related to hiding a portion of the screen before a screenshot is taken, not disabling the screenshot altogether. – Krejko Jul 18 '16 at 15:38
-
@Krejko, you got what I meant to say. – Omkar Amberkar Jul 18 '16 at 15:57
-
@Krejko I flagged as unclear probably – OneCricketeer Jul 18 '16 at 16:14
2 Answers
7
Add the following code to your onCreate
:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE,
WindowManager.LayoutParams.FLAG_SECURE);
setContentView(R.layout.activity_main2);
//...rest of your code
}

Bill
- 4,506
- 2
- 18
- 29
0
Edit: This answer does not work. I thought about deleting the answer, but then thought it would better serve as information to anyone searching this in the future. I am not sure why it doesn't work. Intuitively to me, it should.
Use the onPause
lifecycle method to set the views you need hidden to either invisible or gone using setVisibility()
@Override
protected void onPause() {
TextView tv = (TextView)findViewById(R.id.mytextview);
tv.setVisibility(View.INVISIBLE);
super.onPause();
}

MrSalmon
- 89
- 1
- 5
-
-
1
-
my guess is that the thumbnail cache is created before `onPause` is called – Bill Jul 15 '16 at 20:44
-