Android Activity finished testen

T

Tomate_Salat

Gast
Hi,

Ich möchte gerade ein paar Tests für meine Android-App schreiben. Dabei ist es Möglich, in den Einstellungen festzulegen, ob man über den Back-Key die App beenden kann oder eben nicht.

Das funktioniert auch soweit, nur würde ich das gerne auch Testen können. Jetzt ist mir allerdings nicht klar, wie ich testen kann, ob eine Activity beendet ist. Eine Methode [c]isFinished[/c] gibts ja leider nicht und etwas entsprechendes habe ich nicht gefunden.

Wie würdet ihr es Testen, ob eine Activity und/oder gar eine Applikation eben beendet wurde?
 

eRaaaa

Top Contributor
activity_lifecycle.png

Quelle: Activity | Android Developers
 
T

Tomate_Salat

Gast
Der Lifecycle ist mir bekannt. Hier geht es ja nicht darum, wie ich eine Activity schreibe, sondern darum: diese zu testen. In meinem Fall existiert die ja bereits und Funktioniert auch.
 
T

Tomate_Salat

Gast
So zur Info, meine Lösung:
Java:
private boolean finished=false;

@Override
public void finish() 
{
	finished=true;
	super.finish();
}

public boolean isFinishedCalled()
{
	return finished;
}

+ der Test:
Java:
public void testBackButton()
{
	preferences=PreferenceManager.getDefaultSharedPreferences(activity);
	preferences.edit().putBoolean(KEY_BACKBUTTON_KILL_APP, false).commit();		
	sendKeys(KeyEvent.KEYCODE_BACK);		
	
	assertFalse(activity.isFinishedCalled());
	
	preferences.edit().putBoolean(KEY_BACKBUTTON_KILL_APP, true).commit();
	sendKeys(KeyEvent.KEYCODE_BACK);

	assertTrue(activity.isFinishedCalled());	
}
 
Ähnliche Java Themen
  Titel Forum Antworten Datum
W JSONARRAY per Intent an andere Activity übergeben und umwandeln ggbf. Android & Cross-Platform Mobile Apps 1
M Activity einer anderen App mit result Android & Cross-Platform Mobile Apps 2
CT9288 Methode von Fragment durch Activity rufen scheitert Android & Cross-Platform Mobile Apps 7
ruutaiokwu Android Daten von "Activity A" nach "Activity B" umleiten? Android & Cross-Platform Mobile Apps 13
L Android Lockscreen-Sperrmuster activity verwenden Android & Cross-Platform Mobile Apps 1
J Android App stürzt ab wenn neue activity gestartet Android & Cross-Platform Mobile Apps 6
D Android Activity wechseln per Button Android & Cross-Platform Mobile Apps 3
P Android Android-App Crash - Unable to start activity ComponentInfo Android & Cross-Platform Mobile Apps 2
S Neue Activity lässt sich nicht starten Android & Cross-Platform Mobile Apps 28
B Android Activity nach gedrückte Returntaste weiterlaufen lassen Android & Cross-Platform Mobile Apps 2
J Probleme mit ViewPager und Activity Android & Cross-Platform Mobile Apps 1
B Android In einem View der ersten Activity zweite anzeigen Android & Cross-Platform Mobile Apps 2
G Accelerometer ohne Activity Android & Cross-Platform Mobile Apps 8
J Android BroadcastHandler extends BroadcastReceiver; auf Activity zugreifen? Android & Cross-Platform Mobile Apps 5
K Android Übergeordnete Activity herausfinden? Android & Cross-Platform Mobile Apps 7
W Android Designfrage / Layout / Activity / Fragments Android & Cross-Platform Mobile Apps 2
B Login Activity Android & Cross-Platform Mobile Apps 1
M Android Suche Activity/View Namen Android & Cross-Platform Mobile Apps 1
K Unbekannte Menge von Daten (Strings oder Ints) an Activity übergeben Android & Cross-Platform Mobile Apps 0
M Fehler ohne Sinn? java.lang.RuntimeException: Unable to start activity ComponentInfo Android & Cross-Platform Mobile Apps 11
S Android Eclipse erstellt keine main Activity Android & Cross-Platform Mobile Apps 4
B java.lang.RuntimeException: Unable to start activity ComponentInfo Android & Cross-Platform Mobile Apps 2
K Android Activity for result aus Dialog Android & Cross-Platform Mobile Apps 1
S Android "Weiches wechseln" zwischen Views in einer Activity Android & Cross-Platform Mobile Apps 3
D Android Activity mit mehreren Views "spliten" Android & Cross-Platform Mobile Apps 10
G Activity-Wechsel bitte ohne Notification Android & Cross-Platform Mobile Apps 6
G eine Methode einer anderen Activity aufrufen Android & Cross-Platform Mobile Apps 9
D Android Neue Activity im TabWidget laden Android & Cross-Platform Mobile Apps 8
S Android In Service überprüfen ob eine Activity gebunden ist? Android & Cross-Platform Mobile Apps 6
T Activity / Application fundamentals Android & Cross-Platform Mobile Apps 4
M Activity wechseln aus List View mit Android & Cross-Platform Mobile Apps 2
G extends Activity für Berechnungen? Android & Cross-Platform Mobile Apps 7
G Daten von einer Activity zur nächsten übergeben Android & Cross-Platform Mobile Apps 6
G selbes Menü auf jeder Activity Android & Cross-Platform Mobile Apps 4
C Activity ohne Aktion starten Android & Cross-Platform Mobile Apps 8
C Android Kommunikation zwischen Service und Activity Android & Cross-Platform Mobile Apps 8
Maxim6394 [ Android ] Activity ändern Android & Cross-Platform Mobile Apps 9
A Activity Intent 'source not found' Android & Cross-Platform Mobile Apps 4
A Android Activity Variablen-Initialisierung Android & Cross-Platform Mobile Apps 8
A Beenden einer 2ten Activity Android & Cross-Platform Mobile Apps 3
W Standard Gallery Activity? Android & Cross-Platform Mobile Apps 22
schlingel Android: Overlay in Activity Android & Cross-Platform Mobile Apps 3
G Activity beenden Android & Cross-Platform Mobile Apps 2
M Android Studio - App auf dem Smartphone testen Android & Cross-Platform Mobile Apps 7
A JSRs testen Android & Cross-Platform Mobile Apps 4

Ähnliche Java Themen

Neue Themen


Oben