Question

EDIT: Turns out I just didn't put break; between cases so I've removed my code since it was a basic error.

Was it helpful?

Solution

You have forgotten the break statements

switch(position) {
       case 0:
          Intent one = new Intent(MainActivity.this, BookDetails.class);
          one.putExtra("jsonUrl", "url 1 here");
          startActivity(one);
          one.removeExtra("jsonUrl");
          break;          // here
       case 1:
          Intent two = new Intent(MainActivity.this, BookDetails.class);
          two.putExtra("jsonUrl", "url 2 here");
          startActivity(two);
          two.removeExtra("jsonUrl");
          break;      // here
       case 2:
          Intent three = new Intent(MainActivity.this, BookDetails.class);
          three.putExtra("jsonUrl", "url 3 here");
          startActivity(three);
          three.removeExtra("jsonUrl");
          break;         // here

Without breaking out of the switch the statements can just go through to the next condition.

OTHER TIPS

you are not using the break on the switch.

 switch(position) {
           case 0:
              Intent one = new Intent(MainActivity.this, BookDetails.class);
              one.putExtra("jsonUrl", "url 1 here");
              startActivity(one);
              one.removeExtra("jsonUrl");
              **break;**
           case 1:
              Intent two = new Intent(MainActivity.this, BookDetails.class);
              two.putExtra("jsonUrl", "url 2 here");
              startActivity(two);
              two.removeExtra("jsonUrl");
              **break;**

....

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top