1

Use case is when user enters it's info in edittext and intentionally or unintentionally user sends the application in background. In such case I don't want to display edittext info in recent apps list screenshot and when user again resume the app I want to populate same info in edittext.

Akhil
  • 829
  • 1
  • 11
  • 26
  • Have a look on this Link : http://stackoverflow.com/questions/9822076/how-do-i-prevent-android-taking-a-screenshot-when-my-app-goes-to-the-background – KishuDroid Jun 14 '16 at 12:58

4 Answers4

4

Another option is:

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

But this also dissallows screenshots (not sure if u want that)

to use this add the following line to your onCreate() :

getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);

------------------------EDIT-------------------------

If u want to show the application in the "recent apps" list, but without the editText, than u might want to do something like this:

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);
}

------------------------EDIT-------------------------

Or u can change the complete thumbnail:

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.

So create ur own thumbnail

@Override
public boolean onCreateThumbnail (Bitmap outBitmap, Canvas canvas) {
    Bitmap myBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.myBitmap);
    canvas.drawBitmap(myBitmap, 0, 0, null);

    return true;
}

Good luck!

Community
  • 1
  • 1
Strider
  • 4,452
  • 3
  • 24
  • 35
0

You can use the activity lifecycle callback methods to clear (.clear()) or populate (.setText("some text")) the EditText.

onResume : the user sees and can interact with the activity.

onPause : the activity is partially or totally in background.

You could save the info as a shared preferences in MODE_PRIVATE for the current activity.

SharedPreferences sharedPreferences;

sharedPreferences = getPreferences(Context.MODE_PRIVATE);

write a shared pref

SharedPreferences.Editor editor = sharedPreferences.edit();

editor.putString("INFO", "some text");

editor.commit();

read a shared pref

String info = sharedPreferences.getString("INFO", "default value");

So you can read the SP in onResume and write it in onPause, just before you clear the EditText content.

Alexandre Martin
  • 1,472
  • 5
  • 14
  • 27
  • Thanks for the answer! Was using the same method, clearing edittext in onPause and updating it in onResume. But the problem is somehow android records the screen state before I clear the edittext in onPause. – Akhil Jun 14 '16 at 14:17
  • You could add this tag to any activities that should not show in Recent Apps. : android:excludeFromRecents="true" – Alexandre Martin Jun 14 '16 at 14:26
  • Otherwise, there is another option. You could clear content in onPause before you called the super class. – Alexandre Martin Jun 14 '16 at 14:27
  • android:excludeFromRecents="true" will not help me, will give a shot to other option. Thanks! – Akhil Jun 14 '16 at 14:34
0

in the async task on execute add these lines 1. If u want to hide edittext box theneditext.setVisibility(View.INVISIBLE); or 2.if u want to clear the content theneditext.clear();

VYSHAK M
  • 86
  • 5
0

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

It will destroy the trace.

OR if you want to show blank view in the recent list then:

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.

Hope it will solve your problem.

KishuDroid
  • 5,411
  • 4
  • 30
  • 47