Shinobi Charts for Android with Android 4.4 KitKat


#1

Has much testing been done on 4.4?  I am seeing quite a few errors, and fatal exceptions being spewed from Shinobi on all 4.4 devices, was there any fundamental change which needs to be accounted for?

They seem to all come back to this point:

12-12 13:56:46.186: E/AndroidRuntime(30905): java.lang.NullPointerException
12-12 13:56:46.186: E/AndroidRuntime(30905): at com.shinobicontrols.charts.r.onSurfaceChanged(SourceFile:136)
12-12 13:56:46.186: E/AndroidRuntime(30905): at com.shinobicontrols.charts.GLTextureView$f.l(SourceFile:1539)
12-12 13:56:46.186: E/AndroidRuntime(30905): at com.shinobicontrols.charts.GLTextureView$f.run(SourceFile:1267)

#2

edit: ignore this edit, original posts still holds true :slight_smile:


#3

I also notice that on another Activity the graph continues to grow, as in the X-Axis increases, but no data is ever plotted.  Leaving this activity leads to this crash.  Works on  4.0, and 4.1 and did on 4.2 but I dont have one handy to test on at the moment.


#4

Hi AEB,

Yes, we do run all our tests on a variety of devices, including a Nexus 10 with 4.4. But I don’t think that’s the issue here. That particular exception is usually seen when you use ChartView (rather than ChartFragment) and don’t pass the onPause and onResume calls from your activity through to the ChartView. This is required to ensure that Android hits the onSurfaceCreated/Changed/Destroyed methods in the right order on the chart’s renderer class, which is the class obfuscated as .r. There’s a reasonably complete example of this in the How to: Manage Chart Lifecycles user guide.

Regards,

Robin


#5

Thanks Robin, I didnt mean to imply a lack of testing, I just simply couldnt remeber if 1.2 was released before or after 4.4 was made public.  Was just looking for assurance that it was my fault :slight_smile:  Sounds like you are desribing the issue properly tho, so Ill give it a shot.


#6

Is there an android version of this example you speak of?  I can only seem to find an iOS version


#7

Hi AEB,

Don’t worry, I wasn’t taking your question about testing the wrong way. :slight_smile:

The user guides are in the download bundle, under the docs folder, and there’s a sample app CustomDataAdapterChartView which illustrates it too.

Best regards,

Robin


#8

Hi Robin,

Thanks for the document, very useful, but it has me thinking of a better option for my implementation.  Unforunetly I am forced into using ChartView as the chart sits in a fragment which is controlled by a ViewPager.  But I wondering… is it possible use nested ChartFragments using the support library for <4.2? I’d love to be able to use all the great stuff you’ve done with the fragment encapsulation!


#9

Hi AEB,

It’s not something we’ve tried ourselves but seeing as our SupportChartFragment extends the Frament  in the supoport library, the Android docs suggest it probably would (http://developer.android.com/about/versions/android-4.2.html):

The Android Support Library also now supports nested fragments, so you can implement nested fragment designs on Android 1.6 and higher.

Like I say though, I’ve not actually tried it. Let us know how you get on!

Thanks,

Pat


#10
Hi, I tried what the Android docs suggest (http://developer.android.com/about/versions/android-4.2.html) with SupportChartFragment, unfortunately it did not work because by default, a ChartFragment (so SupportChartFragment is) is retained across Activity re-creation, and i got this exception 03-06 14:57:28.400 [...] E/AndroidRuntime﹕ FATAL EXCEPTION: main Process: [...], PID: 12555 java.lang.IllegalStateException: Can't retain fragements that are nested in other fragments at android.support.v4.app.Fragment.setRetainInstance(Fragment.java:782) at com.shinobicontrols.charts.SupportChartFragmentBase.onCreate(SourceFile:42) at com.shinobicontrols.charts.SupportChartFragment.onCreate(SourceFile:41) at android.support.v4.app.Fragment.performCreate(Fragment.java:1477) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:893) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104) at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682) at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1467) at android.support.v4.app.Fragment.performStart(Fragment.java:1521) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:957) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104) at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682) at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1467) at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:440) at android.os.Handler.handleCallback(Handler.java:733) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5017) 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:779) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) at dalvik.system.NativeStart.main(Native Method) Did someone succeed to use a ChartFragment in a fragment ? Thanks.

#11

Hi ckitop,

As you have found, placing a ChartFragment within another Fragment won’t work for precisely the reason you have seen here - that our ChartFragment/SupportChartFragment is retained across Activity re-creation and the Android framework does not allow retained Fragments within other Fragments.

My suggestion would be to create your own Fragment that contains a ChartView - the layout for this Fragment can consist of just the ChartView; there’s no need for it to sit inside another ViewGroup. You will have to ensure you forward the appropriate lifecycle calls from the Fragment to the ChartView but this doesn’t involve too much work: the most important ones are onPause and onResume - simply override these methods in your Fragment and as well as calling the method on super, also call it on the ChartView.

This should then allow you to put your Fragment inside another Fragment. As it can’t be retained over Activity re-creation you will have to think about how the lifecycle will affect your Fragment and ChartView.

Kind regards,

Patrick


#12

to not have the following issue as previously described. I can’t find the example project you are referring to.

java.lang.NullPointerException

       at com.shinobicontrols.charts.w.onSurfaceChanged(SourceFile:145)

       at com.shinobicontrols.charts.GLTextureView$f.l(SourceFile:1539)

       at com.shinobicontrols.charts.GLTextureView$f.run(SourceFile:1267)

do I just override in my fragment 

public void onResume(){

        super.onResume();

        mChartView.onResume();

    }

    @Override

    public void onPause(){

        super.onPause();

        mChartView.onPause();

    }


#13

Patrick, could you elaborte a little more on adding a ChartFragment into a fragment?

I’m still facing the issue ckitop described (Caused by: java.lang.IllegalStateException: Can’t retain fragements that are nested in other fragments), when I try to add the ShinobiControls ChartFragment to a Fragment.

Any help would be highly appreciated!


#14

Hi Maximillian,

I notice you say that you are trying to place a ShinobiControls ChartFragment into a Fragment. As Pat has mentioned, our ChartFragment/SupportChartFragment is retained across Activity re-creation and the Android framework does not allow retained Fragments within other Fragments.

The solution is to use a ChartView object instead. As Pat mentioned, you would need to place a ChartView inside a Fragment. You’ll need to forward the life-cycle callbacks, such as onPause and onResume to the ChartView object.

For a basic example of how to use a ChartView, look for the project named ‘customdataadapterchartview’ in the ‘samples’ directory of the download bundle. 

I hope this helps, 

Thanks,

Kai