0

コンテキスト: LocationClient が場所をポーリングする前に 2 分間接続できるようにするある種の Timer/AlarmManger メカニズムを作成するにはどうすればよいですか。以下に、場所をポーリングする前に 2 分間遅らせる試みを貼り付けましたが、スリープ モードでは機能しないようです。

考えられる解決策: AlarmManager を使用できます。ただし、これにより 2 番目のサービスを作成する必要があり、単一の LocationClient の参照が非常に複雑になります。この人のアプローチに従うこともできます (バックグラウンド サービスで Google Play Services LocationClient を使用する)。onConnected メソッドで、彼はロケーション ポーリングを実行します。

何を調べるべきかについての推奨事項があれば幸いです

私の onStartCommand メソッドで...

wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "");

    wl.acquire();

    //Getting and Posting Location 
    Log.i("localwordservice", "Creating and Connecting mLocationClient");
    mLocationClient = new LocationClient(this, this, this);
    mLocationClient.connect();

    Timer theTimer = new Timer();
    theTimer.schedule(new TimerTask() {
        @Override
        public void run() {
            if(checkIfGooglePlay()) {
                System.out.println("TIMER is now iniating post location");
                getPostLocation();
                System.out.println("wake lock being released!");
                wl.release();
                System.out.println("The Service is being stopped!");
                stopSelf();
            }
        }
    }, TWO_MINUTES);
4

1 に答える 1