0

Here is the code

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

I have this error :

10-17 15:30:35.288    5467-5467/com.example.android.navigationdrawerexample W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x40cd7930)
10-17 15:30:35.298    5467-5467/com.example.android.navigationdrawerexample E/AndroidRuntime﹕ FATAL EXCEPTION: main
    java.lang.IllegalStateException: Fragment PlanetFragment{41b91f78} not attached to Activity

at this line :

startActivity(browserIntent);

This and this DOESN'T work for me. What i can do ?

Community
  • 1
  • 1
Boris Kuzevanov
  • 1,232
  • 1
  • 12
  • 21

2 Answers2

0

From the exception, it looks like you're calling this method on a Fragment that is not (yet?) attached to an Activity. From the source of the Fragment class:

public void startActivity(Intent intent, Bundle options) {
    if (mActivity == null) {
        throw new IllegalStateException("Fragment " + this + " not attached to Activity");
    }
    ...

To fix this, just change the place where this method is called, i.e. after onAttach() and before onDetach().

matiash
  • 54,791
  • 16
  • 125
  • 154
0

Why don't you just call getActivity() from Fragment and then call startActivity() like getActivity().startActivity(intent);

furkan3ayraktar
  • 543
  • 10
  • 18