Ivo Renkema
Ivo Renkema

Reputation: 2198

Settings for a Service

I have an Android App that is a service: it runs in the background invisibly to the user. This is accomplished as follows:

  1. MainActivity starts up an IntentService, and then immediately finishes
  2. All the work is done in the IntentService.
  3. The style theme is fully translucent: android:Theme.Translucent.NoTitleBar.

This works beautifully!

However, I would like to offer the user the possibility to change some settings. This can not be achieved in the usual manner (Preferences) because we have no UI.

I am now considering creating a Custom Account Type for the App. After all, in this manner change settings via the systems Settings App (icon: cog).

However, this is a bit of a hack.

  1. Custom Accounts are for Apps that require Authentication on a server. That does not apply.
  2. Our Apps runs on an Android mini PC, and we ship hundreds of these devices with one single Google Account. Our users do not think of themselves as "users" or "account holders" like they would on their own phone.

I wonder:

Upvotes: 1

Views: 153

Answers (2)

user6657161
user6657161

Reputation: 361

Create an Ongoing (sticky) notification which launches settings activity upon interaction.

Upvotes: 1

CommonsWare
CommonsWare

Reputation: 1006664

we ship hundreds of these devices with one single Google Account

I would expect that Google would be unhappy with your plan.

How other developers have managed changing setting for a service?

Options include:

  • Not having MainActivity finish() immediately, but instead offer settings right there, or via a separate activity accessible from there

  • Having a separate launcher icon for your settings activity

  • If your service is a foreground service, have an action on its Notification that leads to your settings activity

  • If your minSdkVersion is 24 or higher, give your settings activity the following <intent-filter>, so the user can click over to your settings activity from a gear icon on your app's screen in the Settings app:

 

<intent-filter>
  <action android:name="android.intent.action.APPLICATION_PREFERENCES" />
  <category android:name="android.intent.category.DEFAULT" />
</intent-filter>

If Custom Account Types is considered a good idea?

Only if it is an actual account, one that the user would understand. So, in your case, based on your description, this is not a good idea IMHO.

Upvotes: 2

Related Questions