2015-10-07 112 views
-11
10-07 12:53:30.201  477-477/com.example.manikiran.intentex E/AndroidRuntime﹕ FATAL EXCEPTION: main 
    Process: com.example.manikiran.intentex, PID: 477 
    android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want? 
      at android.app.ContextImpl.startActivity(ContextImpl.java:1150) 
      at android.app.ContextImpl.startActivity(ContextImpl.java:1137) 
      at android.content.ContextWrapper.startActivity(ContextWrapper.java:311) 
      at com.example.manikiran.intentex.MainActivity$5.onClick(MainActivity.java:67) 
      at android.view.View.performClick(View.java:4470) 
      at android.view.View$PerformClick.run(View.java:18773) 
      at android.os.Handler.handleCallback(Handler.java:808) 
      at android.os.Handler.dispatchMessage(Handler.java:103) 
      at android.os.Looper.loop(Looper.java:193) 
      at android.app.ActivityThread.main(ActivityThread.java:5341) 
      at java.lang.reflect.Method.invokeNative(Native Method) 
      at java.lang.reflect.Method.invoke(Method.java:515) 
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:830) 
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:646) 
      at dalvik.system.NativeStart.main(Native Method) 
+0

即時得到上執行 –

+1

添加你的代碼,你已經嘗試 –

+2

'AndroidRuntimeException此錯誤:從外部調用startActivity()活動上下文 - 搜索這個錯誤,你會得到http://stackoverflow.com/questions/3689581/calling-startactivity-from-outside-of-an-activity – PPartisan

回答

0

使用此:

button.setOnClickListener(new View.OnClickListener() 
    { 
      public void onClick(View v) { 
      Intent i = new Intent(PresentActivity.this,NextActivity.class); 
      i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
      startActivity(i); 
     } 
    }); 
相關問題