Android 问题切换活动
在我的应用程序中,我有一个普通菜单,我可以从菜单中进行选择并转到不同的视图。简单...
private void gotoSettings()
{
Intent settingsIntent = new Intent(this, SettingsActivity.class);
startActivity(settingsIntent);
}
现在我在主视图中还有一个方法来处理 flings(在视图之间滑动):
Intent intent = new Intent(MainActivity.this.getBaseContext(), CommandActivity.class);
if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH)
return false;
// left to right swipe
if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY)
{
startActivity(intent);
MainActivity.this.overridePendingTransition(R.anim.slideinleft, R.anim.slideoutright);
}
现在这就是事情。在应用程序启动时,如果我处于主活动并选择设置,它会正常工作并进入“设置”活动。但是,如果我跳到“命令”活动,然后跳回到主活动,然后再次选择“设置”,它将再次调用相同的方法:
private void gotoSettings()
{
Intent settingsIntent = new Intent(this, SettingsActivity.class);
startActivity(settingsIntent);
}
但现在它会自动显示“命令”活动而不是“设置”活动。我什至已经调试过并见证了它在 startActivity(settingsIntent); 之后执行上述代码。它不会进入“设置”活动,而是进入“命令”活动。
这非常非常奇怪,因为我告诉它去“设置”,但事实并非如此。一定是和放纵有关,但我没看到……?
In my app, I have a normal menu where I can select from the menu and go to a different view. Simple...
private void gotoSettings()
{
Intent settingsIntent = new Intent(this, SettingsActivity.class);
startActivity(settingsIntent);
}
Now I also have a method in the main view that handles flings (swipes between views):
Intent intent = new Intent(MainActivity.this.getBaseContext(), CommandActivity.class);
if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH)
return false;
// left to right swipe
if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY)
{
startActivity(intent);
MainActivity.this.overridePendingTransition(R.anim.slideinleft, R.anim.slideoutright);
}
Now here is the thing. On app startup, if I am in the main activity and select settings, it works fine and goes to the Settings activity. But if I fling over to the Command activity, then fling back to the main activity, then select Settings again, it will call the same method which does this again:
private void gotoSettings()
{
Intent settingsIntent = new Intent(this, SettingsActivity.class);
startActivity(settingsIntent);
}
But now it automatically shows the Command activity instead of the Settings activity. I've even debugged and have witnessed it go through the above code and right after startActivity(settingsIntent); it does not go to Settings activity, it goes to command activity.
This is very very strange, as I am TELLING it to go to Settings, but it is not. It must have something to do with the fling, but I dont see it....?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可能你需要这样写
而不是
Probably you need to write like this
instead of