作者milochen (N=NP)
看板AndroidDev
标题Re: [问题] Service在开机时启动
时间Thu Jun 23 14:26:11 2011
Sorry, I cannot type Chinese now.
But, here I can start Service easily here
Actually, It's just need to understand INTENT
And there are just three step if you want to start Service at booting
Step 1. In AndroidManifest.xml, add Intent filter for BOOT_COMPLETED
example.
-----------------------------------------
<application ...>
<service ... >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</service>
</application>
-------------------------------------
Step 2. In AndroidManifest.xml open the uses-permission about BOOT_COMPLETED
example.
----------------------------------
<application ...>
</application>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
--------------------------------------
Step 3. print Log to makesure the Service.onCreate() is invoked at booting
example.
--------------------------------
//In XxxxService.java
public void onCreate() {
super.onCreate();
Log.i("SERVICE_WHEN_BOOT", "XxxxService onCreate() is invoked" );
...
}
-----------------------------------
please reboot after install the apk.:)
To open your eclipse DDMS and add a filter of SERVICE_WHEN_BOOT
Then reboot after installing the .apk.
You will see that the string "XxxxService onCreate() is invoked"
appears in SERVICE_WHEN_BOOT filter of eclipse DDMS
Enjoy it :)
※ 引述《sicao (adios)》之铭言:
: 标题: [问题] Service在开机时启动
: 时间: Mon Jun 20 20:44:12 2011
:
: 最近想尝试做这东西
: 但是参考了底下这些范例
:
: http://www.androidenea.com/2009/09/starting-android-service-after-boot.html
: http://www.androidcompetencycenter.com/2009/06/start-service-at-boot/
: http://blog.gregfiumara.com/archives/82
:
: 都没有成功过..
:
: 是范例有问题还是有我没注意到的地方呢
:
: --
:
: 5L36f6d6I5207573K657273206f6E62066Y697265O666f78206172U65207375636b2e
:
: --
:
※ 发信站: 批踢踢实业坊(ptt.cc)
: ◆ From: 111.240.42.43
: → tomap41017:反正只要在onReceive内启动service就好罗!! 06/21 00:50
: → tomap41017:记得注册Receiver以及Intent.RECEIVE_BOOT_COMPLETE 06/21 00:50
: 推 milochen:建议是先找到一个完整的Project能动,之後再参考这些. 06/21 02:48
: → milochen:因为先求能动,再参考些文章昀内容。会比较快理清问题. 06/21 02:50
: 推 jim31837:建议把你的专案丢上来 或至少丢logcat的讯息 06/21 04:52
: → sicao:问题就是找不到可以用的project.. 06/21 08:53
: → sicao:http://www.multiupload.com/SU1ZF9FPEO 这是我照网路上做的 06/21 08:53
: → tomap41017:我不懂你为何要执着於setAction,直接用Intent(context 06/21 14:05
: → tomap41017:, Service.class)不是很欢乐吗? @@ 06/21 14:06
: 推 tomap41017:琣b猜这边改一下应该会过@@ 06/21 14:08
: 推 tomap41017:你的project在开机完成後就出现Exception罗 06/21 14:10
: → sicao:http://www.multiupload.com/BV7EPIBUKV 改这样还是挂.. 06/21 18:53
: → sicao:http://www.multiupload.com/J46JBEBEWI 这个可以跑.. 06/21 18:54
: → sicao:但是一退出就没有在Running Service清单看到它?? 06/21 18:54
: → tomap41017:service.onStarcCommand()return START_STICKY 06/21 19:30
: 推 jim31837:你到StackOverflow问看看 直觉上应该有这类的问题 06/22 00:51
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 115.81.178.163
※ 编辑: milochen 来自: 115.81.178.163 (06/23 14:32)
1F:→ sicao:Thx~I will try it.. 06/23 15:05
2F:→ tomap41017:推!!本来才想写教学的XDD 06/23 19:18
3F:推 f1yingsheep:大推!!!! 10/27 09:41