iniciar AsyncTask por segunda vez

Estoy construyendo una aplicación de Android que count el time desde que se inició una de las actividades, la primera vez que comencé la actividad todo funciona bien, el timer funciona bien y muestra la hora en el TextView. Cuando termino la actividad (volteando el teléfono), y trato de volver a empezar, el timer funciona bien (lo visualizo como un logging) pero la vista de text no cambia

override fun doInBackground(vararg params: Activity): String? { val acc = Accelerometer(params[0]) dealsList.forEach {Log.d("fallDeals", it) } while (true) { sleep(100) publishProgress() Log.i("TAG", "${tiltSensorsValues[0] - acc.xPos!!} ${tiltSensorsValues[1] - acc.yPos!!} ${acc.zPos!!}") if (flippedPhone(acc)) { Log.i("REFRENCES", "${dbRefrences.stateRef}") dbRefrences.stateRef.setValue("empty") addToOldDataTableDatabase() return "Triggenetworking" break } } } private fun flippedPhone(acc: Accelerometer) = (tiltSensorsValues[0] - acc.xPos!! < -4 || tiltSensorsValues[0] - acc.xPos!! > 4 || tiltSensorsValues[1] - acc.yPos!! < -4 || tiltSensorsValues[1] - acc.yPos!! > 4) override fun onPostExecute(result: String?) { super.onPostExecute(result) dbRefrences.currentRef.child(USERS).removeValue() dbRefrences.stateRef.setValue("empty") Toast.makeText(context,setTimer(),Toast.LENGTH_SHORT).show() } //********************************************* //Functions //********************************************* /** * adding the data to the old data table */ private fun addToOldDataTableDatabase() { val oldDataTableRef = dbRefrences.tableRef.child(OLD_DATA) oldDataTableRef.child(gDate()).child(getCurrentTime())?.child(TIME)?.setValue(timer.text) Log.i("My Service", userList.size.toString()) userList.forEach { oldDataTableRef.child(gDate()).child(getCurrentTime())?.child(PARTICIPANTS)?. child(it.userId)?.setValue(it.name) } } private fun gDate(): String { val c = Calendar.getInstance() val df = SimpleDateFormat("dd-MM-yyyy") return df.format(c.time) } /** * return the time that has passed since the group started */ private fun setTimer(): String { val difference = Calendar.getInstance().timeInMillis - startTime val minutes = TimeUnit.MILLISECONDS.toMinutes(difference).rem(60) val seconds = TimeUnit.MILLISECONDS.toSeconds(difference).rem(60) val hours = TimeUnit.MILLISECONDS.toHours(difference).rem(24) Log.i("TAG", "${String.format("%02d", hours)}:${String.format("%02d", minutes)}:${String.format("%02d", seconds)}") return "${String.format("%02d", hours)}:${String.format("%02d", minutes)}:${String.format("%02d", seconds)}" } /** * changing the textView text to the time that has passed since they started */ override fun onProgressUpdate(vararg values: Void?) { super.onProgressUpdate(*values) timer.text = setTimer() } 

por cierto estoy usando kotlin

Solutions Collecting From Web of "iniciar AsyncTask por segunda vez"

La aplicación de timer simple para resolver su problema podría implementarse de esta manera:

 class TimerApp : Application() {//TODO add TimerApp to manifest val startTime: Long by lazy { System.currentTimeMillis() } companion object { lateinit var instance: TimerApp private set } override fun onCreate() { super.onCreate() instance = this } } class FirstActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) //init your views val timerTV = TextView(this) timerTV.postDelayed({ timerTV.text = TimerApp.instance.startTime.getElapsed() }, 1000) } } fun Long.getElapsed(): String { val delta = System.currentTimeMillis() - this //elapsed time in ms TODO("return formatted string") }