Pierre87 Posted February 15, 2010 Share Posted February 15, 2010 Juste une question parce que je suis feignant :P Je connais les diverses méthodes pour exécuter une action dans le thread graphique : - directement dans un élément graphique - Runnable passé à View.post() - Runnable dans un ASyncTask Connaissez vous une autre méthode, aussi simple que le View.post(), mais qui ne demande pas d'avoir accès à une View (comme ASyncTask) ? Merci Quote Link to comment Share on other sites More sharing options...
popolbx Posted February 15, 2010 Share Posted February 15, 2010 yes, essaye ça: si tu es dans une activity Toto, dans laquelle tu fais tourner le thread: Toto.this.runOnUiThread(new Runnable(){ public void run() { }); runOnUIThread est sur le context je suppose. Quote Link to comment Share on other sites More sharing options...
Pierre87 Posted February 15, 2010 Author Share Posted February 15, 2010 Merci pour cette méthode que je ne connaissais pas ! Mais en fait je suis dans mon objet Application :/ Quote Link to comment Share on other sites More sharing options...
Galize Posted February 16, 2010 Share Posted February 16, 2010 J'utilise Handler.post(Runnable) pour ma part Quote Link to comment Share on other sites More sharing options...
Pierre87 Posted February 16, 2010 Author Share Posted February 16, 2010 J'utilise Handler.post(Runnable) pour ma part Et tu es sûr que ça s'exécute dans le Thread graphique ? D'après ce que j'ai lu, il faut l'instancier quand on est dans le Thread UI. Moi je suis dans mon objet Application. Quote Link to comment Share on other sites More sharing options...
Galize Posted February 16, 2010 Share Posted February 16, 2010 Oui, je l'initialise sur le premier appel qui est dans le thread graphique. Quote Link to comment Share on other sites More sharing options...
Pierre87 Posted February 16, 2010 Author Share Posted February 16, 2010 Et tu sais si Application.onCreate() est dans le thread UI ? Quote Link to comment Share on other sites More sharing options...
Pierre87 Posted February 17, 2010 Author Share Posted February 17, 2010 Ok, je viens donc de trouver la méthode qu'il me fallait : Handler.post(Runnable) Et j'instancie mon Handler dans Application.onCreate() Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.