0

Background - I have an app that currently has a lot of methods in MainActivity to pull and upload data to firebase. It's quite a mess with the other app logic in there..

Problem - I would like a separate class filled with server (firebase) access methods that can be called from any activity or fragment and run asynchronously. The class also needs access to context and be able to initialise and store variables.

PS. I'm using kotlin if that helps at all

Edit: Have done more researching to find terms like "utility" and "static" classes which seems like an accurate way to go... If I create a static utility class with Async methods, will that achieve what I'm after? Also, can you initialise and hold variables in a static class?

Thanks :)

Solved After more research and testing, I created an object that holds my methods and variables and just need to pass context into the relevant methods. Then just simply call objectname.methodname()

NicCoe
  • 409
  • 4
  • 17
  • I don't know if this helps you but, usually, AsyncTask is used for doing server related transactions in the background. Check out [this](https://stackoverflow.com/questions/44525388/asynctask-in-android-with-kotlin#44525947) link. – Nandan Desai Jul 23 '18 at 19:40
  • Thanks Nandan. I know a little bit about AsyncTask and Anko, and will be using them for my server transactions.. I just don't know how to have a whole class of methods using AsyncTask, or know how to call each such method from different fragments. Should they be in an object and then I just pass context into the method parameters?? – NicCoe Jul 23 '18 at 20:39
  • Firebase methods should already be asynchronous. Please show your code and maybe someone can help more specifically to your question – OneCricketeer Jul 24 '18 at 02:54
  • Thanks cricket. I didn't actually know that but asynchronous methods aren't really bothering me at the moment. I'd just like a class that doesn't need to be instantiated to just hold my firebase access methods. – NicCoe Jul 24 '18 at 02:58

0 Answers0