Split list into chunks?

Post your questions and help other users.

Moderator: Martin

Post Reply
User avatar
Bluscre
Posts: 145
Joined: 31 Aug 2017 13:58
Location: Germany
Contact:

Split list into chunks?

Post by Bluscre » 04 Nov 2019 03:00

I have a list of all user apps on the device and i'm currently looping over it and executing

Code: Select all

am force-stop <package>
for each item. The problem with that is that even with command timeout set to 1 it's really slow (takes over 2 mins to kill all)

My question is if there's a way (or even better a built in function) to split the list into chunks.

For example the list has 100 items and when i would do

Code: Select all

lists = splitChunks(list, 2);
list1 = lists[0];
list2 = lists[1];
it would return a list containing 2 lists with 50 items each that i can then go through in parallel to speed up the processing
Unofficial AutoMagic Telegram Group: https://t.me/automagicforandroid
Check out my other flows here: https://github.com/Bluscream/AutoMagicFlows or here.

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Split list into chunks?

Post by Desmanto » 05 Nov 2019 18:09

Why don't just loop over the original list based on the length and the output it to another list.

Code: Select all

lists = newList("Alpha", "Bravo", "Charlie", "Delta", "Echo", "Foxtrot");

list1 = newList();
for(i in [0 to length(lists)/2 - 1])
  addElement(list1, lists[i]);
list2 = removeAllElementValues(lists, list1)
BTW, I don't think paralleling up the command can speed it up significantly. But I am curious to see the result.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

Post Reply