久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

  • <tfoot id='7JYN3'></tfoot>

    <legend id='7JYN3'><style id='7JYN3'><dir id='7JYN3'><q id='7JYN3'></q></dir></style></legend>

    <small id='7JYN3'></small><noframes id='7JYN3'>

      <bdo id='7JYN3'></bdo><ul id='7JYN3'></ul>

      1. <i id='7JYN3'><tr id='7JYN3'><dt id='7JYN3'><q id='7JYN3'><span id='7JYN3'><b id='7JYN3'><form id='7JYN3'><ins id='7JYN3'></ins><ul id='7JYN3'></ul><sub id='7JYN3'></sub></form><legend id='7JYN3'></legend><bdo id='7JYN3'><pre id='7JYN3'><center id='7JYN3'></center></pre></bdo></b><th id='7JYN3'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='7JYN3'><tfoot id='7JYN3'></tfoot><dl id='7JYN3'><fieldset id='7JYN3'></fieldset></dl></div>

        帶有 locationListener 回調的 Android 服務

        Android service with locationListener callbacks(帶有 locationListener 回調的 Android 服務)
        <legend id='TGiPu'><style id='TGiPu'><dir id='TGiPu'><q id='TGiPu'></q></dir></style></legend>

              <i id='TGiPu'><tr id='TGiPu'><dt id='TGiPu'><q id='TGiPu'><span id='TGiPu'><b id='TGiPu'><form id='TGiPu'><ins id='TGiPu'></ins><ul id='TGiPu'></ul><sub id='TGiPu'></sub></form><legend id='TGiPu'></legend><bdo id='TGiPu'><pre id='TGiPu'><center id='TGiPu'></center></pre></bdo></b><th id='TGiPu'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='TGiPu'><tfoot id='TGiPu'></tfoot><dl id='TGiPu'><fieldset id='TGiPu'></fieldset></dl></div>

                  <bdo id='TGiPu'></bdo><ul id='TGiPu'></ul>
                    <tbody id='TGiPu'></tbody>

                  <tfoot id='TGiPu'></tfoot>
                • <small id='TGiPu'></small><noframes id='TGiPu'>

                • 本文介紹了帶有 locationListener 回調的 Android 服務的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我有一個安卓應用程序.根據用戶當前的地理位置,我想在后臺獲取一些遠程數據并存儲.我的實現是:

                  I have an android application. Based on the current geo location of user, I want to fetch some remote data in background and store it. My implementation is:

                  在特定的時間間隔,警報會啟動我的服務.服務使用匿名類查詢當前位置并注冊一個 locationListener 回調.在調用 onLocationChanged() 時,我啟動從服務器獲取遠程數據.

                  At specific interval a alarm fires up my service. Service uses an anonymous class to query current location and registers a locationListener callback. On call of onLocationChanged() I initiate the remote data fetch from server.

                  但是,一旦我的服務完成使用匿名類注冊位置偵聽器,它就會按預期返回;因為它不會在完成之前等待回調發生.由于回調需要一些時間并在服務已經返回時進行調用,所以它會拋出一個錯誤:

                  However once my service is done registering the location listener using anonymos class, it returns as expected; as it doesn't wait for callback to happen before finishing. Since callback takes some time and makes a call when service has already returned, it throws an error saying:

                  java.lang.RuntimeException: Handler{43e82510} sending message to a Handler on a dead thread
                  

                  這很好理解.現在對我來說一個快速的解決方法是我可以使用 locationManager 中的 getLastKnownLocation ,因為它不會通過回調響應;但是如果我現在確實想要最新的位置,在服務中而不是活動中怎么辦?如何等待回調發生并停止我的服務返回.

                  Which is quite understandable. One quick workaround for me now is that I can use getLastKnownLocation from locationManager as that doesn't respond back by callback; but what if I do want the latest location right now, in a service and not activity? How can I wait for callback to happen and stop my service from returning.

                  另外,lastKnownlocation 什么時候更新?每次 GPS 注冊一個新位置時;它會更新嗎?我想知道的是,如果它不是最新的,它仍然可以關閉到最新嗎?因為我在 android 模擬器中沒有看到配置后續更新之間的時間段的選項.

                  Also, at what point does lastKnownlocation gets updated? Everytime GPS registers a new location; does it update it? What I want to know is that if it's not latest can it still be closed to latest? As I didn't see an option in android emulator to configure the time period between subsequent updates.

                  非常感謝任何幫助.干杯

                  Any help is much appreciated. Cheers

                  推薦答案

                  但是如果我現在確實想要最新的位置,在服務中而不是在活動中呢?

                  but what if I do want the latest location right now, in a service and not activity?

                  抱歉,這在服務或活動中都是不可能的.例如,如果 GPS 無線電已關閉,而您正在從 GPS 請求位置數據,則需要數十秒才能得到修復,如果您很幸運的話.它可能根本無法修復.

                  Sorry, but that is not possible, in either a service or an activity. For example, if the GPS radio is off, and you are requesting location data from GPS, it will take tens of seconds just to get a fix, and that's if you are lucky. It might not get a fix at all.

                  如何等待回調發生并阻止我的服務返回.

                  How can I wait for callback to happen and stop my service from returning.

                  你沒有.你按照你說的去做:

                  You don't. You do what you said you would do:

                  使用 locationManager 中的 getLastKnownLocation,因為它不會通過回調響應

                  use getLastKnownLocation from locationManager as that doesn't respond back by callback

                  所以,讓您的 Service(希望是 IntentService)檢查 getLastKnownLocation() 是否恰好有一個值.如果是,請使用它.否則,registerLocationUpdates() 使用 PendingIntent 將控制權交還給您的 IntentService.當你得到那個 Intent時,使用該位置并取消注冊更新(假設警報周期很長,比如每小時一次).

                  So, have your Service (which is hopefully an IntentService) check to see if getLastKnownLocation() happens to have a value. If it does, use it. Otherwise, registerLocationUpdates() using a PendingIntent that will pass control back to your IntentService. When you get that Intent, use the location and unregister for updates (assuming the alarm period is nice and long, like, say, once an hour).

                  如果您的鬧鐘是 _WAKEUP 鬧鐘,事情就會變得棘手.然后,您需要按住 WakeLock,以便在您嘗試 GPS 定位時設備不會重新進入睡眠狀態.但是,您需要在某個時候釋放該 WakeLock,如果我們無法獲得 GPS 定位...嗯...嗯,這就是棘手的部分.試圖找出一種干凈的方式來處理這個問題,并將其實現為可重用的組件(例如,LocationAlarmService),這是我的待辦事項列表中的 18,000 項之一.

                  Things get tricky if your alarm is a _WAKEUP alarm. You will then need to hold a WakeLock, so the device does not fall back asleep while you are trying to get a GPS fix. However, you need to release that WakeLock sometime, and if we cannot get a GPS fix...ummm...well, that's the tricky part. Trying to figure out a nice clean way of handling this, and implementing it as a reusable component (e.g., LocationAlarmService), is one of 18,000 items on my to-do list.

                  另外,lastKnownlocation 什么時候更新?每次 GPS 注冊一個新位置時;它 > 更新了嗎?

                  Also, at what point does lastKnownlocation gets updated? Everytime GPS registers a new location; does it > update it?

                  AFAIK,是的.

                  這篇關于帶有 locationListener 回調的 Android 服務的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  Help calculating X and Y from Latitude and Longitude in iPhone(幫助從 iPhone 中的緯度和經度計算 X 和 Y)
                  Get user#39;s current location using GPS(使用 GPS 獲取用戶的當前位置)
                  IllegalArgumentException thrown by requestLocationUpdate()(requestLocationUpdate() 拋出的 IllegalArgumentException)
                  How reliable is LocationManager#39;s getLastKnownLocation and how often is it updated?(LocationManager 的 getLastKnownLocation 有多可靠,多久更新一次?)
                  CLLocation returning negative speed(CLLocation 返回負速度)
                  How to detect Location Provider ? GPS or Network Provider(如何檢測位置提供者?GPS 或網絡提供商)
                    <bdo id='vFT2g'></bdo><ul id='vFT2g'></ul>
                        <tbody id='vFT2g'></tbody>

                      1. <small id='vFT2g'></small><noframes id='vFT2g'>

                        • <i id='vFT2g'><tr id='vFT2g'><dt id='vFT2g'><q id='vFT2g'><span id='vFT2g'><b id='vFT2g'><form id='vFT2g'><ins id='vFT2g'></ins><ul id='vFT2g'></ul><sub id='vFT2g'></sub></form><legend id='vFT2g'></legend><bdo id='vFT2g'><pre id='vFT2g'><center id='vFT2g'></center></pre></bdo></b><th id='vFT2g'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='vFT2g'><tfoot id='vFT2g'></tfoot><dl id='vFT2g'><fieldset id='vFT2g'></fieldset></dl></div>
                          <legend id='vFT2g'><style id='vFT2g'><dir id='vFT2g'><q id='vFT2g'></q></dir></style></legend>

                            <tfoot id='vFT2g'></tfoot>
                            主站蜘蛛池模板: 成人一级视频在线观看 | 视频在线亚洲 | 精品国产欧美一区二区 | 青青久草| 亚洲欧洲一区二区 | 午夜免费视频观看 | 亚洲欧美一区二区三区在线 | xx性欧美肥妇精品久久久久久 | 日韩精品在线观看一区二区 | 全免费a级毛片免费看视频免 | 亚洲vs天堂| 伊人伊成久久人综合网站 | 一级欧美 | 午夜三区 | 综合视频在线 | 国产精品免费播放 | 99国产视频| 在线视频日韩 | 九九热精品免费 | 四虎最新视频 | 欧美成人a| 亚洲视频中文字幕 | 一区二区三区国产在线观看 | 黄色在线观看国产 | 亚洲最新在线视频 | 中文日韩在线 | 欧美日韩电影免费观看 | av一级一片 | 国产精品一区视频 | 欧美日韩在线观看一区二区三区 | 亚洲日日夜夜 | 在线播放中文字幕 | 99亚洲精品视频 | 九九精品在线 | 欧美一区二区在线观看 | 亚洲精品久久久久久久久久吃药 | 天天操天天插天天干 | 香蕉久久久 | 国产黄视频在线播放 | 久久成人精品视频 | 在线观看视频h |