0

I have a overlay view over all apps. I want to close the overlay view from screen on soft key press (home, back and recent). I have a transparent activity with no content which is starting a service having overlay view.

    public class SampleOverlayShowActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        startService(new Intent(this, SampleOverlayService.class));
    }

    @Override
    protected void onPause() {
        SampleOverlayService.stop();
        finish();
        super.onPause();
    }
}

Inside manifest

<activity
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name"
            android:name="SampleOverlayShowActivity"
            android:excludeFromRecents="true"
            android:theme="@android:style/Theme.Dialog" >
            <intent-filter >
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

Everything is working fine expect recent apps. Activity still show up on recent application button press. It got removes when I again press recent application button.

Ajeet
  • 1,540
  • 1
  • 17
  • 30

1 Answers1

1

This should be much simpler than trying to override soft key behaviour to do clean up. Instead make sure the activity is launched so that it has no recents trace. From the manifest that means adding noHistory and excludeFromRecents

<activity android:excludeFromRecents="true"
          android:noHistory="true"
          android:name=".."
          ...>
     <intent-filter>
            ...
     </intent-filter>
</activity>

Note that android:excludeFromRecents works for the task only, so you probably want to make sure that activity is a new task too, using the appropriate flags (android:launchMode="singleTask")

Nick Cardoso
  • 20,807
  • 14
  • 73
  • 124
  • So you are saying I should have a new activity which is finishing the application having android:excludeFromRecents="true" and android:noHistory="true" – Ajeet Dec 30 '15 at 21:58
  • I'm not sure what you're saying. I am saying that the transparent activity that is excludeFromRecents should also be noHistory and singleTask – Nick Cardoso Dec 30 '15 at 23:00
  • I tried it with the noHistory and singleTask. It is still not working. I am still able to see my app on recent application. – Ajeet Dec 31 '15 at 11:06