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);
精彩评论