我的问题是......如果我们尝试在 startActivity() 之后执行一些代码,我们会在调用当前 Activity 的 onPause() 之前完全执行吗?也就是说,我不知道当包含它的方法到达末尾时是否会实际调用 startActivity() (方法发生的事情finish()
)。
我有一个示例,其中我想要detach()
一个对象(具有数据库连接)后基于某些条件启动一个新的活动,但我需要这个对象来评估一个条件。我知道我可以检查该条件并将布尔值存储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();
}