私の質問は... startActivity() の後にコードを実行しようとすると、現在のアクティビティの onPause() が呼び出される前に完全に実行されますか? つまり、startActivity() を含むメソッドが最後に到達したときに実際に呼び出されるかどうかはわかりません (メソッドで発生する何かfinish()
)。
detach()
いくつかの条件に基づいて新しいアクティビティが開始された後にオブジェクト (データベース接続を持つ) が必要な例がありますが、1 つの条件を評価するにはこのオブジェクトが必要です。detach()
その条件を確認し、最初の の前にブール値とそれを保存できることはif
わかっていますが、次のコードが「合法」かどうかを知りたいです。
ありがとう!
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
School selectedSchool = new School((Cursor)l.getItemAtPosition(position));
mSharedPreferences.edit()
.putLong(DatabaseManager.SCHOOL_ID, selectedSchool.getIdOpenErp())
.commit();
School.SchoolManager schoolManager = new School.SchoolManager(this);
Long[] sessionIdsOpenErpOfSelectedSchool = schoolManager.getSessionIdsOpenErp(selectedSchool);
if (sessionIdsOpenErpOfSelectedSchool.length > 0) {
if (schoolManager.isPreviousWorkingSchoolPresent()) { // line 10
Intent iParticipationManagement = new Intent(this, ParticipationManagement.class);
startActivity(iParticipationManagement);
} else {
Intent iSelectExistingSession = new Intent(this, SelectExistingSession.class);
startActivity(iSelectExistingSession);
}
} else {
Intent iSelectNewSession = new Intent(this, SelectNewSession.class);
startActivity(iSelectNewSession);
}
// The following line will be executed after one of the startActivity() methods is called...
// Is this legal? Or should I get the value from isPreviousWorkingSchoolPresent() (at line 10)
// before the first if and do the detach() there as well?
schoolManager.detach();
}