开发者

Android Issue switching activities

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 a开发者_JAVA百科ctivity, 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....?


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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜