You said you didn't want to use a translucent Activity, but that seems to be the best way to do this:
1- In your Manifest, set the Activity theme to Theme.Translucent.NoTitleBar.
2- Don't bother with a layout for your Activity, and don't call setContentView().
3- In your Activity's onCreate()
, start your Service with startService()
.
4- 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.
how to hide luncher icon :
PackageManager p = getPackageManager();
ComponentName componentName = new ComponentName(this, com.apps.MainActivity.class); // activity which is first time open in manifiest file which is declare as <category android:name="android.intent.category.LAUNCHER" />
p.setComponentEnabledSetting(componentName,PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
Hide open button couldn't be done , because we are talking about an application and not a google library
how to unhide icon :
PackageManager p = getPackageManager();
ComponentName componentName = new ComponentName(this, com.apps.MainActivity.class);
p.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
IMPORTANT: It's somehow tricky if you need to do something with main activity in your app when it's hidden. you will face an ActivityNotFoundException
. to make it work, you should unhide icon before doing anything to your main activity and hide it again after you are finished.