0

Each time I swipe there will be a new page loaded now I had everything working in portrait first and now I am trying to get it working with landscape and portrait. But when I rotate my screen I will get a NullPointerException on my Dialog.

The function causing it inside MainActivity's innerclass FragmentStatePagerAdapter :

@Override
    public void onPageSelected(int position)
    {
        // TODO Auto-generated method stub
        currentSelectedFragmentPosition = position;
        frag.onPageVisible(currentSelectedFragmentPosition);
            frag2.onPageVisible(currentSelectedFragmentPosition);
            frag3.onPageVisible(currentSelectedFragmentPosition);
    }

The function inside the fragment :

public void onPageVisible(int position)
{
     startNewAsyncTask();           
}

The dialog is instantiated inside the onCreateView and logs back that it is not null. When I log inside onPageVisible it does log back null and when I do mProgress = new ProgressDialog(getActivity()); inside the onPageVisible it will still give a nullpointer but then on that line instead.

I really don't understand why it should be set in the onCreateView.

enter image description here

Community
  • 1
  • 1
Shishi
  • 601
  • 2
  • 8
  • 27

2 Answers2

0

Assuming you are using DialogFragment, Android will re-create the dialog for you in onCreate. You can find the existing dialog by the tag in onCreate if your savedInstanceState is not null.

Greg Ennis
  • 14,917
  • 2
  • 69
  • 74
0

If you don't want to recreate your activity or fragment then just simply override onConfigurationChanged(){} method in your class which is extending Activity class.

This method will retain the state of your app whenever you change the orienation of your from to portrait to landscape or vice versa.

Udit Kapahi
  • 2,277
  • 1
  • 27
  • 25
  • I don't really mind recreating as long as it works problem is that the dialog is set to null in the function or something. – Shishi Mar 17 '14 at 11:56
  • I am not able to understand the last portion of your question buddy , are you trying to fetch data inside a Dialog Box? – Udit Kapahi Mar 17 '14 at 12:00
  • The Dialog only displays that the AsyncTask is loading data. It works fine before the orientation change but after it will throw a NullPointerException so I'm searching a way to recreate it or get it back – Shishi Mar 17 '14 at 12:05