1

CommonsWare の例を使用して WakefulIntentService を実装しようとしています。Location を WakefulIntentService のサブクラスに渡す必要がありますが、それができませんでした。

以下を使用して sendWakefulWork を呼び出します。

Intent i = new Intent(context, WakefulIntentService.class);
i.putExtra(Constants.LOCATION, location);
WakefulIntentService.sendWakefulWork(context, i);

WakefulIntentService クラスには、次のメソッドがあります。

public static void sendWakefulWork(Context context, Intent i) {
    getLock(context).acquire();
    i.setClass(context, ProtocolController.class);
    context.startService(i);
}

そして最後に、ProtocolController クラス:

public class ProtocolController extends WakefulIntentService {

    public ProtocolController() {
        super(ProtocolController.class.getSimpleName());
        Log.d(Constants.TAG, "starting Protocol");
    }

    @Override
    public void onCreate(){
        super.onCreate();
    }

    @Override
    protected void doWakefulWork(Intent intent) {
        Log.d(Constants.TAG, "Doing wakeful work");
    }
}
4

1 に答える 1

0

あなたがしようとしている方法で Location オブジェクトを渡すことはできないと思います。putExtra を使用して、緯度と経度、タイムスタンプなど、必要な個々の値を渡します... putExtra を使用して、文字列、浮動小数点数、整数、ブール値などの基本的な値を渡します...

于 2011-06-20T21:39:46.017 に答える