Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. class AuthorizationSaveTask : AsyncTask<Int, Int, String>() {
  2.  
  3. override fun onPreExecute() {
  4.  
  5. }
  6.  
  7. override fun doInBackground(vararg params: Int?): String {
  8.  
  9. val startId = params[0]
  10.  
  11. //Get data for list view
  12. var authorizationArrayList = ArrayList<AuthorizationObject>()
  13. try {
  14. //Set target file to authorizations.txt
  15. val targetFile = File(filesDir, "authorizations.txt")
  16. //Create new file input stream
  17. val fis = FileInputStream(targetFile)
  18. //Create new object input stream, using fis
  19. val ois = ObjectInputStream(fis)
  20. //write object input stream to object
  21.  
  22. //TODO: There has to be a better syntax than this.
  23. authorizationArrayList = (ois.readObject() as ArrayList<*>).filterIsInstance<AuthorizationObject>() as ArrayList<AuthorizationObject>
  24. //close object output stream
  25. ois.close()
  26. //close file output stream
  27. fis.close()
  28.  
  29. } catch (e: ClassNotFoundException) {
  30. e.printStackTrace()
  31. } catch (e: IOException) {
  32. e.printStackTrace()
  33. }
  34. return "Service complete $startId"
  35. }
  36.  
  37. override fun onProgressUpdate(vararg values: Int?) {
  38. super.onProgressUpdate(*values)
  39. val counter = values[0]
  40. Log.i("BEAU", "Service Running $counter")
  41. }
  42.  
  43. override fun onPostExecute(result: String) {
  44. Log.i("BEAU", result)
  45. }
  46.  
  47. class AuthorizationSaveTask : AsyncTask<Int, Int, String>(val context: Context)
  48.  
  49. val task = AuthorizationSaveTask(this)
  50.  
  51. class AuthorizationSaveTask : AsyncTask<Int, Int, String>(val saveDir: File)
  52.  
  53. val task = AuthorizationSaveTask(filesDir)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement