ChartViews interact with the life-cycle of the Activity/Fragment they are hosted in


#1

In the landing screen of the app we have four charts created using Shinobichart library inside four gridview. On click of an icon in the topmost right hand side of the action bar a dialog pops up with “yes ”and ”no” option. On click of “yes” option Annotator screen displays on top of the landing screen but the Shinobi chart becomes invisible and once the Annotator screen goes off then again Shinobichart becomes visible.

As per my analysis the issue is with the Shinobi ChartViews interaction with the life-cycle of the activity/fragment they are hosted in. In one Activity I am using ChartFragment and in other Fragment I am using ChartView. I am facing the same issue once the Annotator screen displays . As per the below link from the ShinobiControls.com userguide ChartFragment takes care of the Activity onResume and onPause but in my case I still have the problem. I tried to follow the approach for ChartView mentioned in the link below but didnt get the scuccess.

https://www.shinobicontrols.com/docs/ShinobiControls/ShinobiChartsAndroid/1.7.2/Premium/Normal/user-guide/how-to-manage-chart-lifecycles.html

May be I am doing something wrong or my analysis is not correct.Can someone please help me in finding the solution for the issue or at least guide me.

Thanks in Advance  smiley small

Rashmi

 


#2

Hi Rashmi,

I think the issue here may be related to the Activity containing the chart being paused because it is in the background. When a dialog appears on top of the chart containing Activity I’m pretty sure onPause will be called. If you are using a ChartFragment then this onPause signal will be automatically passed on to the chart. With ChartView you have to manually forward on the onPause call. This is required for the necessary clean up to be performed on the OpenGL rendering components that the chart uses. By forwarding calls to onResume everything is set up correctly again when the Activity is brought back in to focus.

However, it sounds like here your Annotator is appearing after the Dialog - is this another Activity or Dialog in itself (rather than just being a View over the ChartView in the original Activity)? If this is the case it probably means the chart containing Activity has not yet been resumed and so the charts are not displaying. To be fair I would have expected the charts to have remained on screen in this situation but it sounds like this isn’t the case.

There are a number of areas you could look at:

  • Call onPause() on the ChartView from the onStop() method in the Activity, and equally call onResume() from the onStart() method. It’s not something I’ve tried myself and if you do go down this route I would make sure you do a lot of testing around the life-cycle of your app to ensure there are no unexpected consequences. Ultimately, onPause() should be going to onPause() (and onResume() to onResume()). This would also mean you wouldn’t be able to use the ChartFragment as you won’t be able to prevent the life-cycle forwarding on that.
  • Take snapshots of the charts and place them in ImageViews when the chart containing Activity is put in the background.
  • Make the Annotator a View in the chart containing Activity’s View hierarchy - my thinking is that onResume() will have been called on the Activity so the charts should be correctly rendered.

I hope that gives you some pointers.

Kind regards,

Patrick