Android: How to switch between Activities like switching desktops in Home app?

user237076 picture user237076 · Jul 10, 2010 · Viewed 17k times · Source

I'm developing an Android Application that has three very similar Activities. I would like the user to be able to switch between them by swiping left and right on the screen. This is how I managed that up to now:

I followed this post

Then I changed the method onSwipe() in this way:

@Override
 public void onSwipe(int direction) {
  Intent intent = new Intent();

  switch (direction) {

  case SimpleGestureFilter.SWIPE_RIGHT:
   intent.setClass(this, TodoTodaySheet.class);
   break;
  case SimpleGestureFilter.SWIPE_LEFT:
   intent.setClass(this, TrashSheet.class);
   break;

  }
  startActivity(intent);
 }

It works but I'm not completely satisfied with this. Moreover, I don't know if this is the correct approach.

I would like to have a behavior like the one on Home apps, when switching desktop. Therefore I would like a smoother animation and the appearance of the called activity from the right direction, eg. from the left side of the screen when swiping on the right.

Any hints? Thank you very much.

Answer

Al Sutton picture Al Sutton · Jul 10, 2010

The home screen doesn't scroll between activities it only scrolls between differing views as you can see in its' source code (line 298 is where the screens are changed).

If you're switching between activities you're at the mercy of the users configuration & the devices abilities as to what happens to the display during the transition, so there isn't a lot you can do.