用例是当用户在 edittext 中输入它的信息并且用户有意或无意地在后台发送应用程序时。在这种情况下,我不想在最近的应用列表屏幕截图中显示 edittext 信息,当用户再次恢复应用时,我想在 edittext 中填充相同的信息。
最佳答案
另一种选择是:
FLAG_SECURE - treat the content of the window as secure, preventing it from appearing in screenshots or from being viewed on non-secure displays.
More details here
但是这也禁止截图(不确定你是否想要)
要使用它,请将以下行添加到您的 onCreate()
中:
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
------------------------编辑-------------------- ------
如果你想在“最近的应用程序”列表中显示应用程序,但没有 editText,那么你可能想做这样的事情:
private string mySecretText;
@Override
public void onPause() {
super.onPause(); // Always call the superclass method first
//Now we remember the text
mySecretText = myEditText.getText().toString();
//Optional save it in your Shared Preferences
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
SharedPreferences.Editor editor = preferences.edit();
editor.putString("secretText", mySecretText);
editor.apply();
//Remove the text from the editText
myEditText.setText("");
}
@Override
public void onResume() {
super.onResume(); // Always call the superclass method first
//Optional load it from your Shared Preferences
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
mySecretText = preferences.getString("secretText", "Default"); //U can remove default if u want
myEditText.setText(mySecretText);
}
------------------------编辑-------------------- ------
或者您可以更改完整的缩略图:
onCreateThumbnail - Generate a new thumbnail for this activity. This method is called before pausing the activity, and should draw into outBitmap the imagery for the desired thumbnail in the dimensions of that bitmap. It can use the given canvas, which is configured to draw into the bitmap, for rendering if desired.
Important!: The default implementation returns fails and does not draw a thumbnail; this will result in the platform creating its own thumbnail if needed.
所以创建你自己的缩略图
@Override
public boolean onCreateThumbnail (Bitmap outBitmap, Canvas canvas) {
Bitmap myBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.myBitmap);
canvas.drawBitmap(myBitmap, 0, 0, null);
return true;
}
祝你好运!
关于android - 想要在 Activity 进入后台之前清除 EditText 内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37812333/