Issue
I have the following scenario in my application. There is no UI in my application; instead there is a Service which starts on boot up and will continuously run.
How can I configure my manifest file without a main Activity? Can I launch my app without any Activity? And on launching my app, my Service should start. Is this possible?
I don't want to make a translucent Activity to start the Service.
Solution
You said you didn't want to use a translucent Activity, but that seems to be the best way to do this:
- In your Manifest, set the Activity theme to
Theme.Translucent.NoTitleBar
. - Don't bother with a layout for your Activity, and don't call
setContentView()
. - In your Activity's
onCreate()
, start your Service withstartService()
. - Exit the Activity with
finish()
once you've started the Service.
In other words, your Activity doesn't have to be visible; it can simply make sure your Service is running and then exit, which sounds like what you want.
I would highly recommend showing at least a Toast notification indicating to the user that you are launching the Service, or that it is already running. It is very bad user experience to have a launcher icon that appears to do nothing when you press it.
Answered By - Darshan Rivka Whittle
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.