Android Dialog wird nicht sofort angezeigt

AquaBall

Top Contributor
Meine Activity startet über eine Button eine andere Activity, läuft wunderbar.

Aber wenn ich davor noch einen Dialog öffnen will, dann erscheint der erst im letzten Augenblick und wird sofort von der Activity überlagert. Ich komm gar nicht dazu, etwas auszuwählen.

Nach dem ich Activity 2 wieder schließe wartet der Dialog immer noch geduldig.

Was mach ich falsch?
 

AquaBall

Top Contributor
Java:
        AlertDialog.Builder dialog = new Builder(this);
        dialog.setTitle("Wähle einen Text");
        dialog.setItems(mTextList, new DialogInterface.OnClickListener(){
            public void onClick(DialogInterface dialog, int which){
                auswahl = mTextList[which];
            }
        });
        dialog.show();                      // Dialog SOLLTE! angezeigt werden
        Editor edit = preferences.edit();   // Auswahl als preferece speichern 
        edit.putString("Auswahl",auswahl);
        edit.commit();
        try
        {  Thread.currentThread();
            Thread.sleep(3000);              // Pause (nur für Test) nützt auch nichts, Dialog kommt nicht!
        }
        catch (InterruptedException e) { }
        
        Intent intent = new Intent( this, NeueActivity.class );
        //TODO !!!!!!!!!!!!!  activity wartet Dialog nicht ab !!!!!!!!!!!!!
        startActivity(intent);
.
 
Zuletzt bearbeitet:

schlingel

Gesperrter Benutzer
Ist klar, wenn du nämlich den UI-Thread schlafen legst, tut sich auch im Dialog nichts. Du musst hier auf den Benutzer reagieren und nicht sequentiell aufschreiben was passieren soll.

Starte die neue Activity einfach nach dem der Benutzer ein Item verwendet hat. Wenn der Dialog sich schließen soll nachdem der Benutzer ein Item ausgewählt hat funktioniert das so:

Java:
dialog.setItems(mTextList, new DialogInterface.OnClickListener(){
            public void onClick(DialogInterface dialog, int which){
                auswahl = mTextList[which]; // falls Instanzvariable nicht mehr nötig würde ich sie entfernen
                Editor edit = preferences.edit();   // Auswahl als preferece speichern 
                edit.putString("Auswahl",auswahl);
                edit.commit();
                dialog.dismiss();
                Intent intent = new Intent( this, NeueActivity.class );
                startActivity(intent);                
            }
        });

Wenn du den Dialog anders schließen möchtest, tu das und füg einen Dismiss-Listener hinzu auf den du reagieren möchtest.
 

AquaBall

Top Contributor
Tja, in der Tat bin ich nicht gewohnt, dass das ja einen eigenen thread startet.

Zur Zeit meines ersten Programmes gab's so was noch gar nicht.

Danke für die Info!
 

schlingel

Gesperrter Benutzer
Interessant dass sich das Android-Framework derart geändert hat bzw. dass es so seltsam designed war am Anfang.

Nichts für ungut aber hier im Unterforum sind vor allem Anfänger unterwegs außer ein paar Ausnahmen wie Tomate_Salat, also nichts für ungut ;-)
 

jf

Bekanntes Mitglied
Interessant dass sich das Android-Framework derart geändert hat bzw. dass es so seltsam designed war am Anfang.
AquaBall meint ja, schon programmiert zu haben, als die meisten hier noch nicht lebten. - Damit war sein erstes Programm wohl nicht in Java geschrieben, was ja erst 1995 veröffentlicht wurde. Andorid hat er mit seiner Aussage bzgl. der Threads daher sicher nicht gemeint.

Was hast du bisher denn überwiegend programmiert AquaBall?
 

AquaBall

Top Contributor
Du möchtest ein paar private Daten?

Meine ersten Programm wurde in diesem Stil geschrieben, (wo bei "geschrieben" schon der falsche Audruck ist):
Code:
      PROGRAM TEST 
C                        
C     MEIN ERSTES PROGRAMM
C          
      DO 100 I = 1, 3
      WRITE (*,*) 'HALLO WELT!'
 100  CONTINUE            
      END

Und mein erstes kommerzielles Programm (ca. 5-7 Jahre danach):
Code:
 program Hallo(output);
 begin
  writeln('Hallo Welt');
 end.
 

jf

Bekanntes Mitglied
Der Stil des kommerziellen Programmes drüfte duch die Sprache Pascal gefordert wurden sein.
(zumindest glaube ich mich daran erinnern zu können, dass ich so oder so ähnlich in Turbo Pascal programmiert habe - ist aber schon eine kleine Weile her... ;)

Beim ersten Programm muss ich aber raten: Fortran?
 
Ähnliche Java Themen
  Titel Forum Antworten Datum
L Dialog anzeigen wenn auf Button gedrückt wird. Android & Cross-Platform Mobile Apps 4
R Android Dialog verstecken, statt zu schliessen Android & Cross-Platform Mobile Apps 7
J Input Dialog - ist das so richtig ? Android & Cross-Platform Mobile Apps 1
L Leerer Dialog Android & Cross-Platform Mobile Apps 0
B Android Alert Dialog mit sound oder Android & Cross-Platform Mobile Apps 1
J Dialog in Fragment Android & Cross-Platform Mobile Apps 6
B Senden via Dialog? Android & Cross-Platform Mobile Apps 6
K Android Activity for result aus Dialog Android & Cross-Platform Mobile Apps 1
N Android Retain Dialog verschwindet beim drehen Android & Cross-Platform Mobile Apps 4
T Android - Toast Dialog oder was anders? Android & Cross-Platform Mobile Apps 3
A Android Probleme mit Dialog Android & Cross-Platform Mobile Apps 4
L Custom Dialog Button event Android & Cross-Platform Mobile Apps 2
I modaler Dialog Android & Cross-Platform Mobile Apps 2
W Reward Ads AdMob wird nicht ausgeliefert. Android & Cross-Platform Mobile Apps 9
J Spinner wird nicht aktualisiert Android & Cross-Platform Mobile Apps 6
Naxon89 Duplicate class kotlin - und dies ohne das es angewendet wird Android & Cross-Platform Mobile Apps 1
ImageView wird nicht angezeigt Android & Cross-Platform Mobile Apps 4
W Bildschirm Nutzung Überwachen der App Nutzer ink. was angeklickt wird Android & Cross-Platform Mobile Apps 35
N XY-Plottet keine Daten obwohl Funktion ausgeführt wird Android & Cross-Platform Mobile Apps 4
K Null-Pointer-Exception in ListView - wird über Datenbank gefüllt Android & Cross-Platform Mobile Apps 1
R Android Do not disturb: Sound wird nicht abgespielt Android & Cross-Platform Mobile Apps 2
O Google Admob Ad wird nicht geladen und App stürzt ab Android & Cross-Platform Mobile Apps 1
M Paper DB wird in Android Studio nicht erkannt Android & Cross-Platform Mobile Apps 7
R Audio wird nur 1 Mal abgespielt Android & Cross-Platform Mobile Apps 2
A GraphView => X- und Y-Achse wird nicht angezeigt Android & Cross-Platform Mobile Apps 5
A jpg wird im Android Studio nicht akzeptiert Android & Cross-Platform Mobile Apps 3
Arif Android Radiobutton wird nicht deaktiviert Android & Cross-Platform Mobile Apps 1
Arif Android Canvas wird nicht gezeichnet? Android & Cross-Platform Mobile Apps 0
J Notification wird nicht angezeigt wenn App nicht offen ist. Android & Cross-Platform Mobile Apps 6
M TypedArray-Resource wird falsch geladen Android & Cross-Platform Mobile Apps 7
W Preview wird nicht korrekt angezeigt Android & Cross-Platform Mobile Apps 0
B Profilpic wird nach anmeldung nicht angezeigt. Android & Cross-Platform Mobile Apps 2
K Methode wird nicht gefunden Android & Cross-Platform Mobile Apps 1
J Kamera - Foto wird nicht gespeichert Android & Cross-Platform Mobile Apps 2
V Android Wird mein Vorhaben funktionieren? (Apk Datei decompilieren, bearbeiten, compilieren) Android & Cross-Platform Mobile Apps 2
G App wird nach Installation auf Smartphone beendet Android & Cross-Platform Mobile Apps 1
S Android neue Version des Programms wird nicht in Emulator geladen Android & Cross-Platform Mobile Apps 1
O Android Switch Widget wird nicht angezeigt Android & Cross-Platform Mobile Apps 1
M Android ListView wird nicht dargestellt Android & Cross-Platform Mobile Apps 2
N PriceScannerApp: warum wird nach dem Scannen Display gleich schwarz? Android & Cross-Platform Mobile Apps 4
P Herausfinden, welches Fragment gerade angezeigt wird. Android & Cross-Platform Mobile Apps 1
M Android Nur erste Zeile wird vom Server empfangen Android & Cross-Platform Mobile Apps 0
A App wird bei start des Timers beendet Android & Cross-Platform Mobile Apps 1
A Wieso wird die App beendet ??? Android & Cross-Platform Mobile Apps 2
B Alle Daten gehen verloren, wenn die Displaysperre aktiviert wird? Android & Cross-Platform Mobile Apps 21
P trotz invalidate() wird onDraw() nicht aufgerufen Android & Cross-Platform Mobile Apps 15
W XML Layout: wann wird geladen? Android & Cross-Platform Mobile Apps 10
K Android Temperaturconverter, R.id.element wird nicht gefunden Android & Cross-Platform Mobile Apps 20
A onDraw wird nicht aufgerufen Android & Cross-Platform Mobile Apps 14
W ImageView wird nicht angezeigt Android & Cross-Platform Mobile Apps 19
T Android: ListView-Adapter: Adapter wird ständig aufgerufen Android & Cross-Platform Mobile Apps 2
F Android Datenbank upgrade wird nicht durchgeführt Android & Cross-Platform Mobile Apps 2
F Android R.raw wird nicht gefunden Android & Cross-Platform Mobile Apps 5
P ID wird nicht erzeugt Android & Cross-Platform Mobile Apps 2
C Problem Device/Emulator wird nicht erkannt Android & Cross-Platform Mobile Apps 3
R Zeichen-Codierung in (SMS) TextMessage, "_" wird § Android & Cross-Platform Mobile Apps 2
W MoveEvent reagiert nicht Game Android & Cross-Platform Mobile Apps 1
W Cookie Manger übermittelt nicht Android & Cross-Platform Mobile Apps 1
M PythonInterpreter funktioniert nicht richtig NoClassDefFoundError Android & Cross-Platform Mobile Apps 1
I Android SharedPreferences wenn App auf externem Speicher klappt nicht Android & Cross-Platform Mobile Apps 0
W Frisch generiertes Projekt Value nicht findbar NavController Drawer Android & Cross-Platform Mobile Apps 12
W WebView Linkvertise lädt nicht richtig oder bleibt grau Android & Cross-Platform Mobile Apps 10
W AlertDialog Eigenschaften existiert nicht mehr. Android & Cross-Platform Mobile Apps 14
W Wieso gehen Log nicht im Service? Android & Cross-Platform Mobile Apps 20
I Android ListView (Custom) soll auf Hardwaretasten nicht reagieren. Android & Cross-Platform Mobile Apps 10
CT9288 Zufällige Zahlengenerierung scheint nicht richtig zu funktionieren Android & Cross-Platform Mobile Apps 5
M App crasht und ich bekomme es nicht behoben.:( Android & Cross-Platform Mobile Apps 17
K Android Android In-App-Purchase lädt nicht Android & Cross-Platform Mobile Apps 0
Besset Android http request an interne ip adresse funktioniert nicht Android & Cross-Platform Mobile Apps 8
R Android Visualizer engine kann nicht initialisiert werden Android & Cross-Platform Mobile Apps 3
OSchriever Navigation drawer Strings ändern sich nicht Android & Cross-Platform Mobile Apps 0
W Code läuft unter SDK 27 aber nicht SDK 30 Android & Cross-Platform Mobile Apps 17
N Android Ich kann mit meiner App nicht auf die Datenbank zugreifen Android & Cross-Platform Mobile Apps 4
ruutaiokwu Android Selbst entwickelter SMTP-Client läuft auf PC, nicht aber auf Android Android & Cross-Platform Mobile Apps 9
W Android Wieso geht getApplicationContext() bei Toast, aber nicht bei AlertDialog.Builder? Android & Cross-Platform Mobile Apps 36
A Android Studio: while-Schleife beginnt nicht Android & Cross-Platform Mobile Apps 5
T Android SDK-Manager startet nicht in Eclipse Android & Cross-Platform Mobile Apps 5
J Download und speichern mit jsch klappt nicht Android & Cross-Platform Mobile Apps 5
J Service starte nicht mehr Android & Cross-Platform Mobile Apps 13
J Firebase und Emulator startet nicht Android & Cross-Platform Mobile Apps 2
L ListView aktuallisiert sich nicht Android & Cross-Platform Mobile Apps 15
J ArrayAdapter zeigt Liste nicht an Android & Cross-Platform Mobile Apps 0
L Android Animationen werden nicht angezeigt Android & Cross-Platform Mobile Apps 0
Excess Android Service läuft nicht in Sandby weiter Android & Cross-Platform Mobile Apps 2
J App funktioniert auf Android 5, auf 6 nicht Android & Cross-Platform Mobile Apps 2
K Log.v geht nicht Android & Cross-Platform Mobile Apps 4
L Android Android Studio - Exportierte APK funktioniert nicht Android & Cross-Platform Mobile Apps 6
L Android Methode funktioniert nicht unter Android Android & Cross-Platform Mobile Apps 3
L Android Java scheint XML nicht zu finden Android & Cross-Platform Mobile Apps 11
J android Spinner funktioniert nicht Android & Cross-Platform Mobile Apps 14
B Android osmdroid möchte nicht das es mapnik herunterlädt Android & Cross-Platform Mobile Apps 2
apple_pie1998 SharedPreferences funktionieren nicht... Android & Cross-Platform Mobile Apps 17
B Android Textdatei laden (klappt nicht) Android & Cross-Platform Mobile Apps 4
S Android null pointer (ich verstehs nicht) Android & Cross-Platform Mobile Apps 2
S Android Emulator startet nicht vollständig. Android & Cross-Platform Mobile Apps 0
S Neue Activity lässt sich nicht starten Android & Cross-Platform Mobile Apps 28
M Notification nicht mehr senden nachdem sie geklickt wurde Android & Cross-Platform Mobile Apps 0
D Android Tabs nutzen - PagerTitleStrip haut nicht hin Android & Cross-Platform Mobile Apps 4
K MediaPlayer Soundklasse Start und Stop (stop funktioniert nicht) Android & Cross-Platform Mobile Apps 1
O Android Anfänger: Quellcode nicht gefunden Android & Cross-Platform Mobile Apps 3

Ähnliche Java Themen

Neue Themen


Oben