I have myProgressTextView in MainActivity.
Inside MainActivity I launch a long process using an asyncTask: MyTask.execute(getApplicationContext(),myProgressTextView)
Using publishProgress and onPostExecute I'm able to update myTextView and works all like a charm.
I have a problem navigating between others activities and return back to MainActivity. Passing again through onCreate of MainActivity myTextView reference is changed and I'm not longer able to update my UI ( myTextView ) from MyTask that is still running. What is the right solution in this case?
In Android, AsyncTask is now deprecated. Google encourages usage of the new android architecture components. If you want to persist the information from the task on screen rotation you should consider using ViewModel and Kotlin coroutines. More information for ViewModel and Kotlin coroutines.