Timer geht nicht

Baxter Stockman

Neues Mitglied
Hallo,

Bin neu in Java und Android und haette mal ne Frage. Ich hab 2 activities, in der ersten wird die zweite aufgerufen, die nur fuer 5 Sekunden gezeigt werden soll und wieder zurueck zure ersten springen soll.

Mein Code fuer den 2. Bildschirm sieht so aus:

Java:
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;


public class Thankyou extends ActionBarActivity {

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.thankyou);

        Thread timer = new Thread(){
            public void run(){
                try{
                    sleep(5000);
                }catch (InterruptedException e){
                    e.printStackTrace();
                }finally{
                    Intent openMain = new Intent("android.intent.action.MAIN");
                    startActivity(openMain);

                }
            }
        };timer.start();


    }
}

Manifest sieht so aus

PHP:
 <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity
            android:name=".Thankyou"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.THANKYOU" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>

Nur wenn ich die app aufuehre startet er zwar die 2. activity aber bleibt dann dort und springt nicht zurueck. Was mach ich falsch?

Danke schon mal!


</application>
 

InfectedBytes

Top Contributor
Activities lassen sich nur vom UI-Thread starten, du versuchst dies jedoch in einem anderen Thread zu tun.

Für sowas bieten sich die Handler von Android an, diese haben z.b. Methode um einen runnable verzögert aufzurufen.

Java:
Handler handler = new Handler();
Runnable r = new Runnable() {
	@Override
	public void run() {
		//star tactivity
	}
};
handler.postDelayed(r, 5000);
 

dzim

Top Contributor
Wenn ich es richtig verstehe, willst du von Activity 2 zu Activity 1 zurück, oder? Wenn ja, ist ein erneutes Öffnen der Ersten eigentlich overkill und ein Aufruf von #finish() sollte genügen...
 
Ähnliche Java Themen
  Titel Forum Antworten Datum
X Android Timer Android & Cross-Platform Mobile Apps 13
B Android Memory Leak: Custom Adapter, Timer Android & Cross-Platform Mobile Apps 9
F Mit Canvas zeichen und durch einen Timer aktualiesieren Android & Cross-Platform Mobile Apps 1
B Timer Android & Cross-Platform Mobile Apps 2
W Android Wieso geht getApplicationContext() bei Toast, aber nicht bei AlertDialog.Builder? Android & Cross-Platform Mobile Apps 36
K Log.v geht nicht Android & Cross-Platform Mobile Apps 4
J R.string.(variable) geht das Android & Cross-Platform Mobile Apps 3
L Android Apache POI: Datei speichern geht nicht Android & Cross-Platform Mobile Apps 1
T Button geht net... Android & Cross-Platform Mobile Apps 2
D Hilfe! es geht um Buttons und Sounds Android & Cross-Platform Mobile Apps 14
S Android LogCat Ausgaben in Schleife geht nicht? Android & Cross-Platform Mobile Apps 2
K Android Alarm Manager (Wakelock? ) geht nicht Android & Cross-Platform Mobile Apps 4
N Android Hilfe string to float geht nicht... Android & Cross-Platform Mobile Apps 4
P Android Programm stürzt ab - Es geht um Netzwerk Android & Cross-Platform Mobile Apps 5
D wie geht Klassenvererbung von Canvas Klassen Android & Cross-Platform Mobile Apps 2
R Meine arctan-Methode geht nicht Android & Cross-Platform Mobile Apps 6
X Anfängerfrage : Form und CommandListener - Warum geht das nicht? Android & Cross-Platform Mobile Apps 5
W MoveEvent reagiert nicht Game Android & Cross-Platform Mobile Apps 1
W Reward Ads AdMob wird nicht ausgeliefert. Android & Cross-Platform Mobile Apps 9
W Cookie Manger übermittelt nicht Android & Cross-Platform Mobile Apps 1
J Spinner wird nicht aktualisiert Android & Cross-Platform Mobile Apps 6
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
ImageView wird nicht angezeigt Android & Cross-Platform Mobile Apps 4
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
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
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
M Paper DB wird in Android Studio nicht erkannt Android & Cross-Platform Mobile Apps 7
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
A GraphView => X- und Y-Achse wird nicht angezeigt Android & Cross-Platform Mobile Apps 5
ruutaiokwu Android Selbst entwickelter SMTP-Client läuft auf PC, nicht aber auf Android Android & Cross-Platform Mobile Apps 9
A Android Studio: while-Schleife beginnt nicht Android & Cross-Platform Mobile Apps 5
A jpg wird im Android Studio nicht akzeptiert Android & Cross-Platform Mobile Apps 3
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
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
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
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 App funktioniert auf Android 5, auf 6 nicht Android & Cross-Platform Mobile Apps 2
J Kamera - Foto wird nicht gespeichert Android & Cross-Platform Mobile Apps 2
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
S Android neue Version des Programms wird nicht in Emulator geladen Android & Cross-Platform Mobile Apps 1
B Android Textdatei laden (klappt nicht) Android & Cross-Platform Mobile Apps 4
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
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
S Umlaute werden trotz UTF-8 nicht angezeigt? Android & Cross-Platform Mobile Apps 6
S SPLIT funktion bei STRING funktioniert nicht! Android & Cross-Platform Mobile Apps 4
J Android Breaking Point in Eclipse hält nicht an? Android & Cross-Platform Mobile Apps 5
J Android SimpleDateFormat parser funktioniert nicht richtig? Android & Cross-Platform Mobile Apps 4
Y Erstes kleines Android Programm will nicht so recht... Android & Cross-Platform Mobile Apps 1
S Foto-app hält galerie nicht aktuell Android & Cross-Platform Mobile Apps 9
D Man sieht nicht ob Button gedrückt wurde! Android & Cross-Platform Mobile Apps 10
L Android Multitouch will einfach nicht, was mach ich falsch? Android & Cross-Platform Mobile Apps 1
B AlarmManager triggert nicht jede Stunde Android & Cross-Platform Mobile Apps 7
B Erste Android-App: setContentView(R.layout.main) funktioniert nicht Android & Cross-Platform Mobile Apps 6
N Android EditText.setError() funktioniert nicht nach Rotation Android & Cross-Platform Mobile Apps 1
K OnItemLongClickListener in ListActivity spricht nicht an Android & Cross-Platform Mobile Apps 8
N Android Display nicht löschen bzw. neu laden Android & Cross-Platform Mobile Apps 2
J Handy bootet nicht mehr richtig Android & Cross-Platform Mobile Apps 2
D Android OnClickListener funktioniert auf LinearLayout nicht Android & Cross-Platform Mobile Apps 6
X Android Warum werden Views nicht gefunden? Android & Cross-Platform Mobile Apps 4
D Android App startet nicht Android & Cross-Platform Mobile Apps 24
F Android ArrayList nicht funktional in Android!? Android & Cross-Platform Mobile Apps 6
E Datenbankanfrage findet Tabel nicht Android & Cross-Platform Mobile Apps 3
schlingel Android Warum man Apps beenden sollte bzw. es nicht tun sollte Android & Cross-Platform Mobile Apps 4
S Auflösungsanpassung funktioniert nicht Android & Cross-Platform Mobile Apps 2
P trotz invalidate() wird onDraw() nicht aufgerufen Android & Cross-Platform Mobile Apps 15
A Werde aus Fehlermeldung nicht schlau.... :-( Android & Cross-Platform Mobile Apps 2

Ähnliche Java Themen

Neue Themen


Oben