实战项目中,需要activity页面返回上一级,测试过程中发现失效。解决方案,在baseActiviy
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
// 这里可以添加逻辑来返回到登录页或其他界面
// 例如,启动一个新的 Intent 来打开登录页
Intent intent = new Intent(this, LoginActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
finish();
return true;
}
return super.onOptionsItemSelected(item);
}
欢迎点赞、收藏、转发。