Firebase Android: onDataChange() event always executed in Main UI Thread?

后端 未结 2 2026
忘了有多久
忘了有多久 2020-12-01 12:34

In an Android application using Firebase, I need to execute long operations in background once Firebase returns a query answer. E.g.:

query.addListenerForSi         


        
2条回答
  •  渐次进展
    2020-12-01 13:27

    Might be a little too late to the party, but if you want Firebase to return call backs on the background thread, you can use the BACKGROUND_EXECUTOR from com.google.firebase.firestore.util.Executors.BACKGROUND_EXECUTOR like

    .addOnCompleteListener(BACKGROUND_EXECUTOR, OnCompleteListener {
       ...
    }
    

    There are other executers as well like -

    DEFAULT_CALLBACK_EXECUTOR
    DIRECT_EXECUTOR 
    

提交回复
热议问题