android-How to run Service in different thread than main thread?

前端 未结 5 1881
旧时难觅i
旧时难觅i 2021-02-18 14:12

I am trying to develop a application in android that consists a service to read the sensor value for multiple hours. When i start the service my device get hang and all the othe

5条回答
  •  猫巷女王i
    2021-02-18 14:34

    Application components (services, activities, etc) always run in main thread, no matter what thread they are started from. Consider starting thread in your Service instead, or use an IntentService.

    In your particular case you might try to register a global BroadcastReceiver for sensor changes, which, in turn,will start an IntentService to put newly acquired values in db, etc.

    Actually, here is the link to similar question solved.

    Again, this is not really a multithreading issue. The whole task must be implemented the other way.

提交回复
热议问题