I want to create an activity that launched without UI on boot and restarted with UI when the user tap the icon.
I don’t want multiple instances of this activity.
How I ensure that when user tap the icon (activity is already running), the app will be restarted (in order to display the UI), and the old instance will be destroyed?
Is “singleTask” will do the job?
I want to create an activity that launched without UI on boot and restarted
Share
singleTask is what you need for the activity to prevent it being loaded multiple times.
To fire something up on device start up you need to do listen for the boot;
with a manifest like;
But if you want any process long running, you need a foreground service;
http://developer.android.com/reference/android/app/Service.html#startForeground(int, android.app.Notification)
Has fantastic documentation on how to get your service into a persistant state. It’s dead simple to get an IntentService going, you just need to override a single method http://developer.android.com/reference/android/app/IntentService.html#onStartCommand(android.content.Intent, int, int)
Then store data perhaps in sharedpreferences or a database and your activity accesses the data store.