开发者

Serious problem in the Android in-app billing example?

开发者 https://www.devze.com 2023-03-07 20:37 出处:网络
I recently published an app on the Android Market and have got some error reports I could not figure out. My app has functionality that can be \"activated\" for a $1 fee, and it is loosely based on th

I recently published an app on the Android Market and have got some error reports I could not figure out. My app has functionality that can be "activated" for a $1 fee, and it is loosely based on the Dungeons example app from Google.

There are a two main problems with the example app that I think will cause problems for a lot of devs.

1) It uses a deprecated method in it's BillingService. The BillingService is app specific and handles RPC communication with the Android Market App. It needs to be around even if your Acitivty is not. It implements this method.

@Override public void onStart(Intent intent, int startId) {}

Instead of the newer

public int onStartCommand(Intent intent, int flags, in开发者_StackOverflowt startId) {}

2) More seriously, the corner case where Intent us null, on onStart/onstartCommand invocations causes a NPE, since the code

String action = intent.getAction();

is Executed in the sample app without any null check.

According to the doc http://developer.android.com/reference/android/app/Service.html#onStart(android.content.Intent, int)

"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."

Since I am a novice Android dev I don't want to cry wolf. Can anyone tell me if the Dungeons sample app is broken, or if I have misunderstood something here?


The apps are not designed to be bug free and resilient to situations, only to demonstrate one aspect. I've noticed a lot of quirks in other examples.

Can't you just add a test for when the intent is null?

As you hinted, your app should use onStartCommand() instead of onStart(), unlike the Dungeon example.

0

精彩评论

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