Android:使用putextras()是必要的Intent Service

时间:2014-04-11 07:49:33

标签: android android-intent service intentservice

我在我的应用程序中使用IntentService。我想知道,在调用startService(intentService)方法之前,是否需要putExtras()。或者我可以在不向intent提供数据的情况下调用startService(intentService)。我想知道这个概念背后的原因。

提前致谢。

2 个答案:

答案 0 :(得分:1)

Is this Necessary to putExtras() before calling to startService(intentService)??

答案是否。

putExtras()用于在ActivitysServices之间传递数据。如果您想将一些数据发送到服务,请使用putExtras()

IntenetService中的同一意图将onStartCommand(Intent intent, int flags, int startId)使用getExtras()方法获取意图中的数据

答案 1 :(得分:0)

没有。这不是必需的。如果要将某些值传递给Intent启动的活动,则只需要使用 putExtras()。否则,使用 startActivity(intent)即可启动活动,而无需实施 putExtras()