Keep UI Thread running when screen is off

前端 未结 1 372
清歌不尽
清歌不尽 2021-01-03 13:05

I\'m making an app that updates the UI through the runOnUiThread(Runnable) method. It is very important that this UI thread continues to run as long as the user has this app

相关标签:
1条回答
  • 2021-01-03 13:40

    I would rather run your code as a Service, and hook it to the Activity having the UI through bindService.

    The other option you have, is to create a WakeLock and maintain the phone on all the time. It may be very hard to the battery, though.

    Check the dev guide entry for bound services and see if it fits your design: http://developer.android.com/guide/topics/fundamentals/bound-services.html

    There are many very good tutorials out there for running services, with varying degrees of complexity. Take a look at some of them here:

    • http://www.vogella.de/articles/AndroidServices/article.html
    • http://marakana.com/forums/android/examples/60.html
    • http://developerlife.com/tutorials/?p=356
    • http://mylifewithandroid.blogspot.com/2008/02/double-life-of-service.html
    0 讨论(0)
提交回复
热议问题