Update activity from a thread

1

I wanted to launch a question in theory mode and know your opinion, on whether it is feasible or not and if so if you consider it good practice or not.

  

Is it possible to update an activity from a thread?

I'm talking about native Android apps.

Thank you.

    
asked by Rafa 23.03.2017 в 21:04
source

1 answer

1
  

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".

    
answered by 23.03.2017 / 21:21
source