灵芸 发布于 2017-01-01 字数 2046 浏览 1095 回复 1


public class BillingService extends Service implements ServiceConnection {
public void onStart(Intent intent, int startId) {
handleCommand(intent, startId); // line 361

* The {@link BillingReceiver} sends messages to this service using intents.
* Each intent has an action and some extra arguments specific to that action.
* @param intent the intent containing one of the supported actions
* @param startId an identifier for the invocation instance of this service
public void handleCommand(Intent intent, int startId) {
String action = intent.getAction();
if (Debug.Yes) {
Log.i(TAG, "handleCommand() action: " + action);
if (Consts.ACTION_CONFIRM_NOTIFICATION.equals(action)) {
String[] notifyIds = intent.getStringArrayExtra(Consts.NOTIFICATION_ID);
confirmNotifications(startId, notifyIds);
} else if (Consts.ACTION_GET_PURCHASE_INFORMATION.equals(action)) {
String notifyId = intent.getStringExtra(Consts.NOTIFICATION_ID);
getPurchaseInformation(startId, new String[] { notifyId });
} else if (Consts.ACTION_PURCHASE_STATE_CHANGED.equals(action)) {
String signedData = intent.getStringExtra(Consts.INAPP_SIGNED_DATA);
String signature = intent.getStringExtra(Consts.INAPP_SIGNATURE);
purchaseStateChanged(startId, signedData, signature);
} else if (Consts.ACTION_RESPONSE_CODE.equals(action)) {
long requestId = intent.getLongExtra(Consts.INAPP_REQUEST_ID, -1);
int responseCodeIndex = intent.getIntExtra(Consts.INAPP_RESPONSE_CODE,
ResponseCode responseCode = ResponseCode.valueOf(responseCodeIndex);
checkResponseCode(requestId, responseCode);

如果你对这篇文章有疑问,欢迎到本站 社区 发帖提问或使用手Q扫描下方二维码加群参与讨论,获取更多帮助。



需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。


泛泛之交 2017-04-03 1 楼


(2)官方对参数intent参数的解释:The Intent supplied to startService(Intent), as given. This may be null if the service is being restarted after its process has gone away, and it had previously returned anything except START_STICKY_COMPATIBILITY.

(3)方法onStart()已经deprecated,在Android 2.0之后被onStartCommand所取代。onStartCommand为了backwards compatibility,默认实现是去call onStart方法,并且会在最后返回START_STICKY or START_STICKY_COMPATIBILITY.

(4)所以你可以选择使用标准的onStartCommand来操作.良好的编程习惯为自己的intent加上null check来避免NullPointerException。