Is it in any way possible to launch an activity from the main function without having a UI? i.e. is there a way to create a sort of \"wrapper\" around another activity, i.e.
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">
I think this would help you a lot:
<activity android:name = "MyActivity"
android:label = "@string/app_name"
android:theme = "@android:style/Theme.NoDisplay" >
If you are not interacting with the UI, what you are trying to do sounds more like an android service.
I had used moveTaskToBack(true)
in onResume()
to put the entire activity stack in background.
You need to add the Intent flag,
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
Or
call "finish();
" after firing the intent.
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"