How to launch an Activity without a UI?
Android also provides a theme specifically for this:
android:theme="@android:style/Theme.NoDisplay"
Just in case you are using Android 6.0+ or Target SDK is 23+, having a theme android:theme = "@android:style/Theme.NoDisplay"
will lead to a crash with error did not call finish() prior to onResume() completing
. This in fact is a bug recognised by Google developers here.
So it is recommended to use an activity with following theme as a workaround.
android:theme = "@android:style/Theme.Translucent.NoTitleBar"
In your manifest, when you declare the activity, use theme "@android:style/Theme.Translucent.NoTitleBar"
Ex:
<activity android:name="yourActivityName" android:label="@string/app_name" android:theme="@android:style/Theme.Translucent.NoTitleBar">
You need to add the Intent flag,
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
Or
call "finish();
" after firing the intent.