Android Studio version 2.3
You can create a Service without the main activity by following a few simple steps. You can install this application through Android Studio and debug it like a regular application.
First create a project in Android Studio with no activity. Then create your service class and add it to your AndroidManifest.xml
<application android:allowBackup="true" android:label="@string/app_name" android:icon="@mipmap/ic_launcher" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <service android:name="com.whatever.myservice.MyService"> <intent-filter> <action android:name="com.whatever.myservice.MyService" /> </intent-filter> </service> </application>
Now, in the drop-down list next to the "Run" button (green arrow), go to "Edit Configurations" and in the "Launch Options" select "Nothing." This will allow you to install your service without Android Studio, complaining of a lack of core activity.
After installation, the service will NOT start, but you can start it with this adb shell command ...
am startservice -n com.whatever.myservice/.MyService
You can check it with ...
ps | grep whatever
I have not tried it yet, but most likely Android Studio will automatically start the service. This will be done in this menu “Edit Configurations”.
Merc Oct 19 '17 at 23:57 on 2017-10-19 23:57
source share