It's simple, I have a fragment, in onCreate I make a post request, then inside onPostExecute

I call: Intent browserIntent = new Intent (Intent.ACTION_VIEW, Uri.parse (this.redirectUrl + "? username =" + getValue (loginString) + "& password =" + getValue (pwdString))); startActivity (browserIntent);

Swears at this line: startActivity (browserIntent); This is what it says:

10-17 15:47:58.015 6146-6146/com.example.android.navigationdrawerexample E/AndroidRuntime﹕ FATAL EXCEPTION: main java.lang.IllegalStateException: Fragment PlanetFragment{41b92d38} not attached to Activity at android.app.Fragment.startActivity(Fragment.java:1046) at android.app.Fragment.startActivity(Fragment.java:1032) at com.example.android.navigationdrawerexample.MainActivity$PlanetFragment$JSONAsyncTask.onPostExecute(MainActivity.java:652) at com.example.android.navigationdrawerexample.MainActivity$PlanetFragment$JSONAsyncTask.onPostExecute(MainActivity.java:389) at android.os.AsyncTask.finish(AsyncTask.java:631) at android.os.AsyncTask.access$600(AsyncTask.java:177) at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:176) at android.app.ActivityThread.main(ActivityThread.java:5319) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869) at dalvik.system.NativeStart.main(Native Method) 

What does it omit to be?

Closed due to the fact that off-topic participants zRrr , Bald , Streletz , Nick Volynkin , Vladimir Glinskikh 11 December '15 at 5:26 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • “Questions asking for help with debugging (“ why does this code not work? ”) Should include the desired behavior, a specific problem or error, and a minimum code for playing it right in the question . Questions without an explicit description of the problem are useless for other visitors. See How to create minimal, self-sufficient and reproducible example . " - zRrr, Bald, Streletz, Nick Volynkin, Vladimir Glinskikh
If the question can be reformulated according to the rules set out in the certificate , edit it .

    1 answer 1

    Fragment PlanetFragment {41b92d38} not attached to Activity

    This means that at the time when startActivity(browserIntent); the fragment is no longer attached to Activiti. Need to do something different. You can tell just by looking at the code.