java - Pass integer to activity from within handler -


i'm working on app in activity shown 3 seconds, after next activity started. succeeded following code:

// shows picture 3 seconds, takes user gameplay      final handler handler = new handler();     handler.postdelayed(new runnable() {         public void run() {              intent intent = new intent(showimage.this, gameplay.class);              showimage.this.startactivity(intent);             showimage.this.finish();         }     }, 3000); 

this activity shows picture , want pass id of picture next activity. know can done (from experience, in activity) using following code (i tried inserting in blank line above):

this.putextra("id", selected_image); 

however, error "the method putextra(string, int) undefined type new runnable(){}"

my question is, how pass image-id next activity, while containing 3-seconds delay?

here rest of activity's code:

import android.content.intent; import android.graphics.bitmap; import android.os.bundle; import android.os.handler; import android.support.v7.app.actionbaractivity; import android.view.menu; import android.view.menuitem; import android.widget.gridview; import android.widget.toast;  public class showimage extends actionbaractivity {  @override public boolean oncreateoptionsmenu(menu menu) {     // inflate menu; adds items action bar if present.     getmenuinflater().inflate(r.menu.show_image, menu);     return true; }  @override public boolean onoptionsitemselected(menuitem item) {     // handle action bar item clicks here. action bar     // automatically handle clicks on home/up button, long     // specify parent activity in androidmanifest.xml.     int id = item.getitemid();     if (id == r.id.action_settings) {         return true;     }     return super.onoptionsitemselected(item); }  @override protected void oncreate(bundle savedinstancestate) {     // shows activity     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_show_image);      // intent data     intent intent = getintent();      // selected image id , crop image     final int selected_image = (integer) intent.getextras().getint("id");     bitmap [] croppedbitmap = createbitmap.createbitmap(this, selected_image, 3);          // create gridview pictures showed in         gridview grid_layout =  (gridview) findviewbyid(r.id.grid_layout);          // pass array pieces image adapter         grid_layout.setadapter(new croppedimageadapter(this, croppedbitmap));          // test text         toast.maketext(this, string.valueof(selected_image), toast.length_long).show();      // shows picture 3 seconds, takes user gameplay      final handler handler = new handler();     handler.postdelayed(new runnable() {         public void run() {              intent intent = new intent(showimage.this, gameplay.class);             this.putextra("id", selected_image);             showimage.this.startactivity(intent);             showimage.this.finish();         }     }, 3000); } } 

change

  this.putextra("id", selected_image); 

to

  intent.putextra("id", selected_image); 

Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -