Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class AuthorizationSaveTask : AsyncTask<Int, Int, String>() {
- override fun onPreExecute() {
- }
- override fun doInBackground(vararg params: Int?): String {
- val startId = params[0]
- //Get data for list view
- var authorizationArrayList = ArrayList<AuthorizationObject>()
- try {
- //Set target file to authorizations.txt
- val targetFile = File(filesDir, "authorizations.txt")
- //Create new file input stream
- val fis = FileInputStream(targetFile)
- //Create new object input stream, using fis
- val ois = ObjectInputStream(fis)
- //write object input stream to object
- //TODO: There has to be a better syntax than this.
- authorizationArrayList = (ois.readObject() as ArrayList<*>).filterIsInstance<AuthorizationObject>() as ArrayList<AuthorizationObject>
- //close object output stream
- ois.close()
- //close file output stream
- fis.close()
- } catch (e: ClassNotFoundException) {
- e.printStackTrace()
- } catch (e: IOException) {
- e.printStackTrace()
- }
- return "Service complete $startId"
- }
- override fun onProgressUpdate(vararg values: Int?) {
- super.onProgressUpdate(*values)
- val counter = values[0]
- Log.i("BEAU", "Service Running $counter")
- }
- override fun onPostExecute(result: String) {
- Log.i("BEAU", result)
- }
- class AuthorizationSaveTask : AsyncTask<Int, Int, String>(val context: Context)
- val task = AuthorizationSaveTask(this)
- class AuthorizationSaveTask : AsyncTask<Int, Int, String>(val saveDir: File)
- val task = AuthorizationSaveTask(filesDir)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement