Java android eclipse, starting activity in thread: application stopped working -


hey doing simple android app , trying start new activity thread this:

 public void startui (){      thread t = new thread(){          public void run () {              runonuithread(new runnable() {                 @override                 public void run() {                     intent gotomenu = new intent(getapplicationcontext(), mainmenu.class);                     startactivity(gotomenu);                 }             });         ;}      };  t.start; } 

but when code comes line

intent gotomenu = new intent(getapplicationcontext(), mainmenu.class); 

it crashes , writes: "application stopped working".

if want start activity need use activity context first parameter. if use application context mainmenu activity must have flag_activity_new_task flag set. cannot start new activity in same task application context.

refer: http://developer.android.com/reference/android/content/intent.html#flag_activity_new_task

as @raghunandan mentioned, if want delay, should use handler this:

uihandler.postdelayed(new runnable() {     @override     public void run() {         intent gotomenu = new intent(getapplicationcontext(), mainmenu.class);         gotomenu.addflags(intent.flag_activity_new_task);         startactivity(gotomenu);     } }, 500); 

Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -

Nuget pack csproj using nuspec -