3

Android マーケットでアプリのプロ キーを購入すると、ユーザーが利用できるプロ機能も含まれる無料のアプリがあります。プロキー アプリに受信機を設定し、メイン アプリに別の受信機を設定しました。ユーザーがメイン アプリの [Validate key] ボタンをクリックすると、インテントがキー アプリの受信側にブロードキャストされ、受信側が IntentService を起動して、プロ キー ライセンスが有効かどうかを確認します。次に、IntentService は、LVL チェックからの「応答」エクストラを含むインテントをメイン アプリ レシーバーにブロードキャストします。

私はほとんどそこにいます。IntentService で LVL チェックを実行しようとしたときにのみ、エラーが発生しました。

W/MessageQueue(2652): java.lang.RuntimeException: Handler{4052de20} sending message to a Handler on a dead thread
W/MessageQueue(2773):   at com.android.vending.licensing.LicenseChecker$ResultListener.verifyLicense(LicenseChecker.java:207)

助言がありますか?

IntentService ソース:

public class CheckerService extends IntentService {

private static final byte[] SALT = ....;
private static final String BASE64_PUBLIC_KEY = ...;
private String device_id;

public CheckerService() {
    super("CheckerService");
}

@Override
protected void onHandleIntent(Intent intent) {
    SharedPreferences data = getSharedPreferences("data", MODE_PRIVATE);
    device_id = data.getString("device_id", null);

    if (device_id == null) {
        SharedPreferences.Editor editor = data.edit();
        device_id = new DeviceId().generate(this);
        editor.putString("device_id", device_id);
        editor.commit();
    }

    ServerManagedPolicy smp = new ServerManagedPolicy(this,
            new AESObfuscator(SALT, getPackageName(), device_id));
    LicenseChecker checker = new LicenseChecker(this, smp, BASE64_PUBLIC_KEY);
    checker.checkAccess(new LicenseCheckerCallback(){

        public void allow() {
            Intent i = new Intent();                
            i.setAction("com.mainapp.intent.action.LICENSE_RESPONSE");
            i.putExtra("response", "LICENSE_OK");
            sendBroadcast(i);
        }

        public void dontAllow() {
            Intent i = new Intent();                
            i.setAction("com.mainapp.intent.action.LICENSE_RESPONSE");
            i.putExtra("response", "LICENSE_NOT_OK");
            sendBroadcast(i);
        }

        public void applicationError(ApplicationErrorCode errorCode) {
            Intent i = new Intent();                
            i.setAction("com.mainapp.intent.action.LICENSE_RESPONSE");
            i.putExtra("response", "LICENSE_ERROR");
            sendBroadcast(i);
        }});

}


@Override
public void onDestroy() {
    super.onDestroy();
    checker.onDestroy();
}
}
4

1 に答える 1

0

この問題は IntentService にあると思います。IntentService は、独自のライフサイクルを管理します。基本的に、これは非 UI スレッドで実行される単なるサービスです。コールバックが処理される前にサービスが破棄されるため、コールバックが発生したときに「コールバック」する対象が存在しません。

START_STICKY または START_NOT_STICKY を使用してサービスで実行し、ライフサイクルを自分で管理することができます。

于 2013-02-07T01:24:06.257 に答える