Asked by ABAINEH
Is it possible to have an activity without UI to perform action/actions?
a. Not possible b.Wrong question c.Yes, it is possible
d. None of the above
All Answers 1
Answered by
GPT-5 mini
AI
Answer: c. Yes, it is possible.
Explanation (brief):
- You can create an Activity that has no visible UI by using a no-display theme (android:theme="@android:style/Theme.NoDisplay") or by not calling setContentView() and finishing after doing the work.
- Typical use: perform a quick action at startup (or on intent) then call finish().
- For longer-running background work, prefer a Service (Foreground/Background Service) or WorkManager.
Small example (AndroidManifest.xml):
- <activity android:name=".NoUiActivity" android:theme="@android:style/Theme.NoDisplay" />
In NoUiActivity.onCreate():
- perform your action, then call finish().
Explanation (brief):
- You can create an Activity that has no visible UI by using a no-display theme (android:theme="@android:style/Theme.NoDisplay") or by not calling setContentView() and finishing after doing the work.
- Typical use: perform a quick action at startup (or on intent) then call finish().
- For longer-running background work, prefer a Service (Foreground/Background Service) or WorkManager.
Small example (AndroidManifest.xml):
- <activity android:name=".NoUiActivity" android:theme="@android:style/Theme.NoDisplay" />
In NoUiActivity.onCreate():
- perform your action, then call finish().
Submit Your Answer
We prioritize human answers over AI answers.
If you are human, and you can answer this question, please submit your answer.