我在做這樣的事情:如何終止活動並切換到另一個活動?
public class MyActivity extends Activity {
@Override
public void onStart() {
super.onStart();
User user = new Entrance().enter();
// continue with user, since it's a valid one
}
}
// I'm using this class from many activities
public class Entrance {
public User enter() {
try {
User user = new Hub().enter();
} catch (AuthenticationFailedException ex) {
this.startActivity(new Intent(this, LoginActivity.class));
this.finish();
}
return user;
}
}
此代碼不起作用,因爲finish()
不拋出異常,讓執行流繼續。這種情況下適當的設計是什麼?
試試「noHistory」在清單MyActivity。 – TeeTracker 2014-09-19 12:37:04
返回null,或拋出異常。 – njzk2 2014-09-19 12:50:04