startService写法
16lz
2022-04-21
用法1:
MainActivity.java
Intent intent = new Intent();
intent.setClass(getApplicationContext(), MyService.class);
startService(intent);
AndroidManifest.xml
<service
android:name="com.example.first.MyService"
android:enabled="true" >
</service>
蓝色:还可是.MyService、MyService
用法2:
MainActivity.java
Intent intent = new Intent();
intent.setAction("com.example.first.MyService");
startService(intent);
AndroidManifest.xml
<service
android:name="com.example.first.MyService"
android:enabled="true" >
<intent-filter>
<action android:name="com.example.first.MyService" />
</intent-filter>
</service>
蓝色:还可是.MyService、MyService
红色:两处保持一致
更多相关文章
- android 颜色16进制对应的xml配置值(工具参考)
- Intent在Android中的几种用法 .
- Android(安卓)handler用法详解二(例2)
- android 6.0权限问题处理的核心代码--shouldShowRequestPermissi
- Android(安卓)IntentService用法和源码分析
- Android(安卓)传感器用法
- Android(安卓)中数据库查询方法query()中的selectionArgs的用法
- Android(安卓)DownloadManager 用法
- android 中RecyclerView 嵌套了 GridView 的用法