This series of posts is all about those small things in Android that you can use and/or abuse for your benefit. Small hidden gems or just simple hacks to overcome some issues. This post is all about the Invisible Activity, the activity without a gui / ui!
Using this theme for your activity will result in your activity being invisible and your icon not showing in the app drawer. If you want the icon to be visible in the app drawer for this activity but still want an invisible activity:
Both implementations have their own right of existence. The first can be used for small actions without showing an actual activity, like when working with widgets. The latter can be useful for wrapper functionality.
But we should also keep in mind that we often do not want the activity to be present in the stack history (otherwise you have pressing back issues), so we should add the following code to the activity tag in the manifest:
But this is not enough, surely no more back pressing issues but the activity is still in the recents list. We do not want that:
From now on you have absolute control over the visibility of your activity. Use it wisely!
PLEASE NOTE: You should end your invisible activity with the finish() command. Also consider this only if you cannot use a service to do the stuff you need.