3

I'm developing a calendar app, and using textview as calendar cell, when i check the logcat after launching the app, i find this message from Choreographer "Skipped 76 frames! The application may be doing too much work on its main thread". i know i'm creating a lot of textviews (120), but how can i build my calendar without affecting my app performance ? is there another way to build a calendar who supports events ?

Blacksword888
  • 61
  • 1
  • 8
  • This has nothing to do about another Calendar that supports events. You just have to move your TextView creations to a background thread. Read up on [AsyncTasks](http://developer.android.com/reference/android/os/AsyncTask.html) on the Android Developers page. But yeah, a different View might lighten the load though/ – tolgap Jul 03 '13 at 22:01
  • Is using a TextView for each Calendar cell the recommended approach? You might want to have a look at the example app to make sure. I'm sure a GridView or TableLayout or some other composite ViewGroup is a better approach than using a bunch of TextViews, and that's exactly why LogCat is complaining – Jade Byfield Jul 03 '13 at 22:01
  • @Jade GridView or TableLayout will both require creating the TextViews... I don't see how that would help. – LuckyMe Jul 03 '13 at 22:06
  • @tolgap that might be the best approach here, however keep in mind only the UI-thread can modify the layout, or at least should. – LuckyMe Jul 03 '13 at 22:06
  • 1
    @LuckyMe you were right with "can" – codeMagic Jul 03 '13 at 22:12
  • 1
    Creating your `TextView`s off the UI thread will save you *nothing*, since you can only add them to the layout from the UI thread and it is the measuring the drawing that takes up all of the time, not object creation. – Joseph Earl Jul 03 '13 at 22:15
  • You may see the link [This describes about Choreographer logs][1] [1]: http://stackoverflow.com/questions/11266535/meaning-of-choreographer-messages-in-logcat – Swapnil Kale Nov 26 '13 at 08:30
  • Use gridview instead of creating textview – Rajendra Apr 25 '15 at 03:14

5 Answers5

1

120 text views seems like a lot, and in particular it seems like several screens worth of data.

When you have multiple screens of data, it would be logical to think about using an adapter view, for example ListView or GridView. Adapter views use view recycling to limit the number of views in use at any given time to approximately one screen's worth.

x-code
  • 2,940
  • 1
  • 18
  • 19
  • This. Look into recycling your views. The Calendars that Google has created do this. Their code is open source. It's worth studying. – Dave Thomas Oct 01 '15 at 04:04
0

Is there a reason you're not using Pickers.

If you need to roll your own control, you'll need to move any heavy lifting to another thread. You can either

1) Use the java Runnable interface or Thread class, probably with an anonymous inner class (see here).

2) Use FutureTask + executor service (here is an example).

Community
  • 1
  • 1
sevensevens
  • 1,703
  • 16
  • 27
  • I'm not using pickers because a i need to display events on my calendar, i need also to click on the events to display some informations (that's why i use textview) – Blacksword888 Jul 04 '13 at 07:52
0

Since you are making a calender, and therefore are aware of the number of cells before hand, considered maybe inflating the layout containing the cells and that way with one command the entire layout is set, and then you just fill in the text of the TextViews?

LuckyMe
  • 3,820
  • 2
  • 27
  • 35
  • that's an interesting idea, but i'm using a custom class inherited from Textview where i need to add some properties to store informations, how can i use it in the XML file ? – Blacksword888 Jul 04 '13 at 08:12
  • O.o now that I don't have experience with, but here is an Android link I found for a start [http://developer.android.com/training/custom-views/create-view.html]. Not sure if it will help but I hope so. I also got some results when I searched for "android custom view xml" in Google. All I can say at this point is Good Luck :P – LuckyMe Jul 04 '13 at 08:19
  • i apreciate your help, thank you ! – Blacksword888 Jul 04 '13 at 08:22
  • No problem, any time :) – LuckyMe Jul 04 '13 at 08:30
0

I did a search and found this link: http://developer.android.com/reference/android/view/Choreographer.html. This is a new class introduced in API 16.

Choreographer lets apps to connect themselves to the vsync, and properly time things to improve performance.

Android view animations internally uses Choreographer for the same purpose: to properly time the animations and possibly improve performance.

Since Choreographer is told about every vsync events, I can tell if one of the Runnables passed along by the Choreographer.post* apis doesnt finish in one frame's time, causing frames to be skipped.

In my understanding Choreographer can only detect the frame skipping. It has no way of telling why this happens.

The message "The application may be doing too much work on its main thread." could be misleading.

You may refer this question

Community
  • 1
  • 1
Shaishav Jogani
  • 2,111
  • 3
  • 23
  • 33
-1

I'd be reluctant to make any changes unless I was CERTAIN that my app was performing badly. I see this message regularly on my emulators, sometimes when Android is still starting up, and sometimes when running simple osample apps supplied by Google. This is worth reading :

Choreographer(697): Skipped 152 frames! Debug log

Community
  • 1
  • 1
IanB
  • 3,489
  • 1
  • 20
  • 24