Aller au contenu
View in the app

A better way to browse. Learn more.

Forum de Frandroid

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Exécuter Runnable dans thread graphique

Featured Replies

Posté(e)

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

Posté(e)

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.

Posté(e)
  • Auteur

Merci pour cette méthode que je ne connaissais pas !

Mais en fait je suis dans mon objet Application :/

Posté(e)
  • Auteur
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.

Posté(e)

Oui, je l'initialise sur le premier appel qui est dans le thread graphique.

Posté(e)
  • Auteur

Et tu sais si Application.onCreate() est dans le thread UI ?

Posté(e)
  • Auteur

Ok, je viens donc de trouver la méthode qu'il me fallait : Handler.post(Runnable)

Et j'instancie mon Handler dans Application.onCreate()

Rejoignez la conversation

Vous pouvez poster maintenant et vous enregistrez plus tard. Si vous avez un compte, connectez-vous maintenant pour poster.

Invité
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Répondre à ce sujet…

Account

Navigation

Rechercher

Rechercher

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.