Android 问题切换活动

发布于 2024-10-31 11:39:36 字数 1239 浏览 0 评论 0原文

在我的应用程序中,我有一个普通菜单,我可以从菜单中进行选择并转到不同的视图。简单...

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

盗心人 2024-11-07 11:39:36

可能你需要这样写

Intent intent = new Intent(MainActivity.this, CommandActivity.class);

而不是

Intent intent = new Intent(MainActivity.this.getBaseContext(), CommandActivity.class);

Probably you need to write like this

Intent intent = new Intent(MainActivity.this, CommandActivity.class);

instead of

Intent intent = new Intent(MainActivity.this.getBaseContext(), CommandActivity.class);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文