Sending message to a Handler on a dead thread when getting a location from an IntentService

后端 未结 3 611
轻奢々
轻奢々 2020-12-01 01:44

My app needs location fixes on regular basis, even when the phone is not awake. To do this, I am using IntentService with the pattern generously provided by Commonsware. htt

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-01 02:04

    For others like me: I had a similar problem related to AsyncTask. As I understand, that class assumes that it is initialized on the UI (main) thread.

    A workaround (one of several possible) is to place the following in MyApplication class:

    @Override
    public void onCreate() {
        // workaround for http://code.google.com/p/android/issues/detail?id=20915
        try {
            Class.forName("android.os.AsyncTask");
        } catch (ClassNotFoundException e) {}
        super.onCreate();
    }
    

    (do not forget to mention it in AndroidManifest.xml:

    
    

    )

提交回复
热议问题