Forum Xamarin.Android

What should be best approach to do background execution

Hi All,

Greetings for the day!

I have legacy .net application on top of which I am doing cross platform app development for iOS using Xamarin.iOS and for Android using Xamarin.Android. I have a recyclerview which can have upto 200 items in it at a time. Each recyclerview item has custom made vertical status bar that represents some color coding based on computational logic executed in background using Task (TPL in .net). You can refer that vertical bar similar to vertical bar shown for each work item on vsts board highlighted in attached photo. For e.g. User story has blue vertical bar, bug has red vertical bar and task is with orange one. I know that my color coding computational logic is not efficient as of now and each calculation takes about 2 seconds which I will try to improve eventually. But as of now for 200 items i spawn 200 different tasks (System.Threading.Task in TPL) and each task takes 2 seconds i.e. about 7 minutes overall (200 items x 2 seconds each). As soon as each task is finished it updates the respective color code on respective recyclerview item using notifychanged method. But these 200 tasks running in parallel has side effect when user tries to navigate to different fragments. (I have single activity which hosts 4 different fragments). App performance is sluggish when user tries to switch between these 4 different fragments since those 200 tasks running in background. So for this problem, Can anybody point me to right choice for executing this background logic? Should it be AsyncTask, Handler, ThreadPool or IntentService? and what is the xamarin.android equivalent for it?

Your response is highly appreciated.

Thanks in advance.

Answers

  • jezhjezh Member, Xamarin Team Xamurai

    There is no best method, but it does exist the most suitable approach .
    Is it convenient for you to post the main code of recyclerview ?

Sign In or Register to comment.