Is it possible to update an activity from a thread?
It is feasible, although it is regularly done outside a Thread
or when the execution of a process is finished (for example onPostExecute()
in a Asynctask
), if you want to open a Activity
from a Thread
, as an option use a Handler using getMainLooper ()
Handler handler = new Handler(Looper.getMainLooper());
handler.post(new Runnable() {
@Override
public void run() {
Intent intent = new Intent (MainActivity.this, OtraActivity.class);
startActivity(intent);
}
});
I would not consider it a good practice, but it depends on the requirements of your application, sometimes it is necessary to make "unicorns".