Search code examples
androidandroid-intentandroid-listviewbroadcastreceiverandroid-wake-lock

App is slowing down [General]


I do have a more general question, without any specific code. I will explain what my application does and how and what issues I can monitor. Maybe one of you had the same issues and can lead me to the problem.

The App:

It reads car diagnostic data (OnBoardDiagnostics) over Bluetooth and shows them in real-time in a ListView. I can start the update function by a "update Button".

How:

Everytime a new value is received via Bluetooth, a background Class (which handles the Stringforming) sends an Intentto notify the UI to update the ListView. The Adapter Class of my ListView has the listening BroadcastReceiver registered and if it gets triggered, it will notify the ListView by notifyDataSetChanged().

Issues:

1.If I use an WakeLock to keep the screen on, the UI refreshing slows down after approx. 10 minutes.

2.If I press the power button, so the screen is off, it still slows down (I can see that, because I send the values to an webserver) but furthermore: If I turn the screen back on. I see the ListView stops for about 20-30 seconds and than normally continues with normal speed (not slow anymore).

So.. I think this is a very general question. I searched for WakeLock and sleep behaviour, but I couldn't find any similar issues. Maybe one of you can give me a hint, what the problem could be. Maybe one of you had a similar problem.

Any hint is appreciated!

EDIT 1:

Maybe the problem of the 2. issue is based on the lifecycles of my objects / activity. If I press the update Button, an AsyncTask is started, which sends the Data (JSON, which contains one new value for all list items) to my Webserver. If the device screen is off, I still get the data every 2 seconds. If I turn on the screen, it stops for these 20-30 seconds as well as the UI. So I think my UI works fine. The Update Intents were sent right.

I have to check if I still receive new values in that background class, mentioned above. Thanks to zapl

Thanks!


Solution

  • Except all possibilities I checked, i came across this article:

    AsyncTasks for long running Operations

    Short: There are some points you need to keep in mind if you are using AsyncTasks in very long running operations (>20min). My Problem was, that I used the AsyncTask as an inner Class. After a long period, when the Activity that created the Task was destroyed, the AsyncTask still kept a reference of this activity.

    After I used a Bus, described in the article above, the UI worked fine!!

    So, if anyone else noticed performance problems of your App, I recommend that article.

    Thanks for all the other hints! Have fun coding!