android - handler.postDelayed application stopped working -


this question has answer here:

my application crash whenever reach toast(parent) part. tried emptying entire run() , there no problem.

this codes work fine in emulator not on device.

please ignore toast if to, main problem not toast codes onwards. crash on device.

im merely using toast know application crashed.

public class loadingactivity extends activity {  /** duration of wait **/ private final int splash_display_length = 2000;  intent intent;  loadingactivity parent;  /** called when activity first created. */ @override public void oncreate(bundle icicle) {     super.oncreate(icicle);     setcontentview(r.layout.activity_loading);      intent = getintent();     parent = this;      imageview logo = (imageview) findviewbyid(r.id.imageview);      textview splash = (textview) findviewbyid(r.id.splash);     splash.settext(intent.getstringextra(constant.splash_text));      translateanimation animator = new translateanimation(logo.getx(), logo.getx(), logo.gety(), logo.gety() + 300);     animator.setduration(2000);     animator.setfillafter(true);     logo.startanimation(animator);      /* new handler start menu-activity      * , close splash-screen after seconds.*/     new handler().postdelayed(new runnable(){         @override         public void run() { //error on here             toast.maketext(parent, "im still fine", toast.length_long).show();             /* create intent start menu-activity. */             intent nextintent = new intent(parent, homeactivity.class);             nextintent.putextra(constant.login_username, intent.getstringextra(constant.login_username));             parent.startactivity(nextintent);             toast.maketext(parent, "passed", toast.length_long).show();             loadingactivity.this.finish();         }     }, splash_display_length); } } 

you cannot use toast(any ui related elements) inside background thread because worker thread doesn't access ui elements , can use activity.runonuithread(runnable) , can use activity context make toast.

toast.maketext(loadingactivity.this, "passed", toast.length_long).show(); 

how display toast inside handler/thread?


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -