What happens to an Android thread after the Activity that created it is destroyed?

前端 未结 4 1884
一向
一向 2021-02-07 04:25

In my Android app, the main Activity will sometimes start a Thread to load data from a server. This thread modifies the app\'s database and edits some important files. AFAIK,

4条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-07 05:20

    You should be using a service:

    Because a process running a service is ranked higher than a process with background activities, an activity that initiates a long-running operation might do well to start a service for that operation, rather than simply create a worker thread—particularly if the operation will likely outlast the activity.

    Take a look here: http://developer.android.com/guide/topics/fundamentals/processes-and-threads.html#Lifecycle (where the text I pasted originates)

提交回复
热议问题