Search code examples
javaandroidtablet

DialogFragment is relaunching itself when startActivity on new Intent is called


In my Android application I have a dialog fragment that contains a ListView. The onclick handler of the items in the list view calls my internalPlayer method which calls a VideoView activity to play a video. The VideoView activity is used in other places within the app so I know it is working.

private void internalPlayer(final String channelUrl)
{
    final Intent localIntent = new Intent(getActivity(), InternalVideoActivity.class);
    localIntent.putExtra(EXTRA_VIDEO_URI, Uri.encode(channelUrl, ALLOWED_URI_CHARS).toString());
    localIntent.putExtra(GridViewFragment.CHANNEL_NAME, mCategory.toString() + " Episode ");
    getActivity().startActivity(localIntent);
}

When running the app in a tablet everything works well and the video activity starts and plays the video. When I run the app on a phone device when I click an item in the ListView the dialog fragment relaunches itself and because the serialized objects originally passed to it no longer exist there is a NullPointerException throw.

Here's the log:

04-16 19:34:33.790    6000-6000/com.xystra W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x41998700)
04-16 19:34:33.790    6000-6000/com.xystra E/MAIN PHONE ACTIVITY: 1﹕ Unable to start activity ComponentInfo{com.xystra/com.xystra.activity.CatchUpSynopsisActivity}: java.lang.NullPointerException
04-16 19:34:33.814    6000-6000/com.xystra E/MAIN PHONE ACTIVITY﹕ STACK TRACE
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xystra/com.xystra.activity.CatchUpSynopsisActivity}: java.lang.NullPointerException
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
            at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3740)
            at android.app.ActivityThread.access$700(ActivityThread.java:141)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1262)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:5103)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:525)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.NullPointerException
            at com.xystra.ui.fragment.ProgramFragment.onCreateView(ProgramFragment.java:369)
            at android.support.v4.app.Fragment.performCreateView(Fragment.java:1786)
            at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:947)
            at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1126)
            at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1108)
            at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:1917)
            at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:544)
            at roboguice.activity.RoboFragmentActivity.onStart(RoboFragmentActivity.java:60)
            at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1171)
            at android.app.Activity.performStart(Activity.java:5143)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
            at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3740)
            at android.app.ActivityThread.access$700(ActivityThread.java:141)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1262)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:5103)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:525)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
            at dalvik.system.NativeStart.main(Native Method)

Any help or ideas are greatly appreciated.

More Info

  • The dialog fragment loads properly. The listview is populated everything is good.
  • When I click an item in the listview my internalPlayer method is called. When getActivity().startActivity(localIntent) is executed the dialog fragment relaunches itself instead of launching the new intent/activity.
  • Because the fragment is relaunching itself, the serialized objects that were originally passed the first time are not available or null so the dialog fragment returns the exception you see above.
  • Everything works perfectly on a tablet. Only on phone devices do I get this event.

Solution

  • Well I got rid of the dialog fragment and used the existing activity fragment for my view, ran some tests and was able to deduce that I had an arithmetic exception in an underlying activity for some reason that was causing the issue. Really don't know how that method got recalled to cause the exception. Thanks for all your help to those who commented.