Naming AsyncTask for profiling in Android

Can I call AsyncTasks in Android for profiling? AsyncTasks is currently only displayed in the profiler as

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

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

+6
source share
1 answer

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

 String oldName = Thread.currentThread().getName(); Thread.currentThread().setName("MY-ASYNC"); ... <your code here> ... Thread.currentThread().setName(oldName); 
+16
source

Source: https://habr.com/ru/post/903450/


All Articles