
我的活动堆栈看起来像这样,原谅粗略的图表!
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 exampleA->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总结
以上是内存溢出为你收集整理的android – 后退按钮关闭两个活动?全部内容,希望文章能够帮你解决android – 后退按钮关闭两个活动?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)