Information: Mein Gerät ist ein Nexus One mit 2.2 und ich habe zwei Projekte getestet, eins auf 1.5 und eins auf 2.1.Probleme, die den Lebenszyklus zu verstehen, wenn der Bildschirm aus- und wieder eingeschaltet
Problem: Ich habe Probleme, den Lebenszyklus meiner Anwendung zu verstehen, wenn der Bildschirm aus- und eingeschaltet wird.
Hier ist mein Ausgang
// activity starts
08-04 17:24:17.643: ERROR/PlayActivity(6215): onStart executes ...
08-04 17:24:17.643: ERROR/PlayActivity(6215): onResume executes ...
// screen goes off
08-04 17:24:28.943: ERROR/PlayActivity(6215): onPause executes ...
08-04 17:24:32.113: ERROR/PlayActivity(6215): onStop executes ...
08-04 17:24:32.113: ERROR/PlayActivity(6215): onDestroy executes ...
08-04 17:24:32.983: ERROR/PlayActivity(6215): onStart executes ...
08-04 17:24:32.983: ERROR/PlayActivity(6215): onResume executes ...
08-04 17:24:32.983: ERROR/PlayActivity(6215): onPause executes ...
// screen goes on
08-04 17:24:47.683: ERROR/PlayActivity(6215): onResume executes ...
// lock removed
08-04 17:24:56.943: ERROR/PlayActivity(6215): onPause executes ...
08-04 17:24:59.663: ERROR/PlayActivity(6215): onStop executes ...
08-04 17:24:59.663: ERROR/PlayActivity(6215): onDestroy executes ...
08-04 17:25:00.943: ERROR/PlayActivity(6215): onStart executes ...
08-04 17:25:00.943: ERROR/PlayActivity(6215): onResume executes ...
ich total verwirrt bin. Warum muss die Aktivität neu gestartet werden, wenn der Bildschirm ausgeschaltet wird? Und warum stoppen und neu starten, wenn der Bildschirm bereits eingeschaltet war und nur die Sperre entfernt wurde?
Um sicherzustellen, dass ich nichts falsch gemacht habe, habe ich ein neues Projekt mit nur dieser Aktivität erstellt. Der Ausgang ist identisch ...
public class LifeCycleTest extends Activity {
private final static String DEBUG_TAG = "FirstLifeLog";
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.e(DEBUG_TAG, "onCreate executes ...");
setContentView(R.layout.main);
}
protected void onRestart() {
super.onRestart();
Log.e(DEBUG_TAG, "onRestart executes ...");
}
protected void onStart() {
super.onStart();
Log.e(DEBUG_TAG, "onStart executes ...");
}
protected void onResume() {
super.onResume();
Log.e(DEBUG_TAG, "onResume executes ...");
}
protected void onPause() {
super.onPause();
Log.e(DEBUG_TAG, "onPause executes ...");
}
protected void onStop() {
super.onStop();
Log.e(DEBUG_TAG, "onStop executes ...");
}
protected void onDestroy() {
super.onDestroy();
Log.e(DEBUG_TAG, "onDestroy executes ...");
}
}
Hat jemand eine Idee?
Update von heute (nicht verstehen, warum es nicht das letzte Mal wie verhält sich, vielleicht auch mehr freie Ressourcen?)
// activity starts
08-09 12:14:03.122: ERROR/FirstLifeLog(15406): onCreate executes ...
08-09 12:14:03.132: ERROR/FirstLifeLog(15406): onStart executes ...
08-09 12:14:03.132: ERROR/FirstLifeLog(15406): onResume executes ...
// screen off
08-09 12:14:07.412: ERROR/FirstLifeLog(15406): onPause executes ...
// screen on
08-09 12:14:11.722: ERROR/FirstLifeLog(15406): onResume executes ...
// no log for removed screen lock
Was ist seltsam ist, dass ich onDestroy(), onStart(), OnResume() -Aufrufe sehe, aber ich sehe keine onCreate() -Aufrufe. Ich bin auch daran interessiert, das Verhalten zu verstehen. –
Das liegt daran, dass mein onCreate die Log-Anweisung verpasst ... Auch habe ich es heute nochmal ausprobiert ... jetzt hat mein Spiel das gleiche Verhalten, aber das Testprojekt hat das erwartete Verhalten (siehe Update) – WarrenFaith