Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Naming AsyncTask for profiling in Android [duplicate]

Is there any way to name AsyncTasks in Android for the purposes of profiling? As of now, the AsyncTasks only shows up in the profiler as

[N] AsyncTask #1
[M] AsyncTask #2
[K] AsyncTask #3
[L] AsyncTask #4
etc...

What I would like to do is to be able to name them in some way to easily identify them in the trace file.

like image 636
Slim Avatar asked Dec 09 '11 12:12

Slim


People also ask

What is the replacement for AsyncTask in Android?

AsyncTask deprecated alternative Android – Java Here, we are using the Executor class as an alternative to the deprecated AsyncTask. First, create an instance of the executor by using any of the factory methods: private final Executor executor = Executors.

What are the three generic types of an AsyncTask?

An asynchronous task is defined by 3 generic types, called Params , Progress and Result , and 4 steps, called onPreExecute , doInBackground , onProgressUpdate and onPostExecute .

What is the method name for executing in background thread for AsyncTask approach?

The basic methods used in an android AsyncTask class are defined below : doInBackground() : This method contains the code which needs to be executed in background. In this method we can send results multiple times to the UI thread by publishProgress() method.

What is the problem with AsyncTask in Android?

In summary, the three most common issues with AsyncTask are: Memory leaks. Cancellation of background work. Computational cost.


1 Answers

You can rename current thread from code that run in the thread. For example, add next code in your doInBackground() function:

String oldName = Thread.currentThread().getName();
Thread.currentThread().setName("MY-ASYNC");
...   
<your code here>
...
Thread.currentThread().setName(oldName);
like image 63
inazaruk Avatar answered Nov 01 '22 07:11

inazaruk