开发者

android service questions

I read this http://developer.android.com/guide/topics/fundamentals/services.html and there it say the lifecylce of the service depends on how I started it either via onStartCommand() and the service runs (almost) for ever or via onBind() and the service only runs as long as my application does.

Now I read http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/app/AlarmService.html there the service is started via the AlarmManager. Neither the onBind() nor the onStartCommand() methods are used. How is the lifecylce of this service now?

Second question, is somehow (how?) ensured that if the application is started again and again that the service is only scheduled once?

开发者_Go百科

Thanks, A.


or via onBind() and the service only runs as long as my application does.

More accurately, it runs until all bindService() calls have matching unbindService() calls.

Neither the onBind() nor the onStartCommand() methods are used

That is not a Service, despite the name. It is an Activity.

Second question, is somehow (how?) ensured that if the application is started again and again that the service is only scheduled once?

The PendingIntent will be equivalent for the two setRepeating() calls, so the second setRepeating() should overwrite the first. That being said, this is a sloppy example.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜