解决了!
我的活动堆栈看起来像这样,原谅粗略的图表!
A-->B-->C '-->D
如果我按下活动B中的后退按钮,我会按预期返回A.
但是,如果我按下活动C或D中的后退按钮,我会返回A而不是B.
在我看来,这可能是由两件事引起的
1)活动B在打开C或D的意图时退出
2)后退按钮以某种方式被调用两次?
我仔细研究了活动B中的点击监听器,这些监听器启动了期望在那里找到一个finish()调用的意图,但没有.我还检查了活动C和D的onBackpressed()方法,看看我是否手动打开活动A ……但我没有.
这是活动A的onResume方法
protected void onResume() { super.onResume(); screenOn(SCREEN_ON_DURATION); mWakeLock.acquire(); }
这是我开始意图C和D的方式
Bundle info = new Bundle(); info.putString("classId",""+classId ); Intent intent = new Intent(Notebook.this,StudentChooser.class); intent.putExtras(info); Notebook.this.startActivity(intent);
有人可以帮忙吗?
编辑:我在onUserLeaveHint()中发现了finish(),这就是问题所在!
解决方法
The reason may be that you are using finish() in your prevIoUs activity,For example A->B->C Intent intent = new Intent(B.this,C.class); startActivity(intent); finish(); finish() is destroying B activity hence the control is going on activity A on back button
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。