0

I'm trying to make an interactive book, where every page contains 2 images and 2 buttons. One image is animated on user touch (that's working fine) The buttons are "Back" and "Next", that's working fine too, but my problem is I have a sequence of 10 classes name one after another:

Class01 Class02 Class03... (Every class has a different animation)

So in class01, next button is always calling the next activity

 public void Next(View v) {
    Intent next = new Intent(this, next_page);
    startActivity(next);
    finish();

and closing the current one, which is Force Closing the app quite regularly. I'm new to android and I think my logic is pretty useless.

How can I implement this sequence?

Violin Nz
  • 297
  • 1
  • 5
  • 15

2 Answers2

1

you can make it using View Flipper to make it more interactive and add animations.

Mohammed Saleem
  • 568
  • 5
  • 20
0

In your case, finish(); isn't necessary, remove it. And you will have:

Next button

public void Next(View v) {
    Intent next = new Intent(this, next_page);
    startActivity(next);
}  

Back button

public void Back(View v) {
    this.finish();
}  

Don't forget, users can press "Back Button" on their device. This may interest you:

public void onBackPressed() {
     // do something if the button back is pressed.
     super.onBackPressed();
}  

I think @MohammedSaleem and @mvnpavan are right when they say you should to use ViewFlipper, more adapted in your case. You will declare in your Manifest just one Activity for all your layouts. See this answer (https://stackoverflow.com/a/3545954/2668136) which says:

ViewFlipper can be used if you want to periodically change the views. Say like an automated flipping book of some sort.

To make a ViewFlipper, you must to read this tutorial:
Creating Image Slideshow Using ViewFlipper

And to see a simple example in this SO answer:
How To Use ViewFlipper With Three Layouts?

Finally, the Google Reference Documentation:
Public Class ViewFlipper

Hope this help.

Community
  • 1
  • 1
Blo
  • 11,903
  • 5
  • 45
  • 99