Reputation: 421
I have an Android application with 2 activities. Each activity has an AsyncTask that communicates with a server using UDP.
public class MainPostTask extends AsyncTask<String, Integer, String> {
@Override
protected String doInBackground(String... params)
{
..... udp comunication here
}
}
I change between these two activities every 20 seconds.
e.g.:
Intent it = new Intent(this, MainActivity.class);
startActivity(it);
The other PostTask is omitted to reduce the text.
After 3 hours, the Android becomes very slow. Sometimes is very hard to close the application. I am sure that I am finishing the AsyncTask before changing activity.
Do you have any idea what is going on? How can I profile the Android to see the memory/cpu and etc?
I also use Log.d(). When I plug the cable all the messages buffered are output to the logcat. Do you think this log messages are causing the problem?
Best regards, Andersan.
Upvotes: 1
Views: 61
Reputation: 1355
You gave few code. Maybe you do not close the connection. Perhaps your task is not removed and fixated. Study the following materials:
Profiling with Traceview and dmtracedump (SO source)
Upvotes: 0
Reputation: 808
Are you always changing activities by calling startActivity? If so, you're stacking activities. Don't do that.
What are you trying to accomplish by switching tasks? Answering that will let us know how to best handle your situation.
Upvotes: 1