0

I will start this by saying that on iOS this algorithm takes, on average, <2 seconds to complete and given a simpler, more specific input that is the same between how I test it on iOS vs. Android it takes 0.09 seconds and 2.5 seconds respectively, and the Android version simply quits on me, no idea if that would be significantly longer. (The test data gives the sorting algorithm a relatively simple task)

More specifically, I have a HashMap (Using an NSMutableDictionary on iOS) that maps a unique key(Its a string of only integers called its course. For example: "12345") used to get specific sections under a course title. The hash map knows what course a specific section falls under because each section has a value "Course". Once they are retrieved these section objects are compared, to see if they can fit into a schedule together based on user input and their "timeBegin", "timeEnd", and "days" values.

For Example: If I asked for schedules with only the Course ABC1234(There are 50 different time slots or "sections" under that course title) and DEF5678(50 sections) it will iterate through the Hashmap to find every section that falls under those two courses. Then it will sort them into schedules of two classes each(one ABC1234 and one DEF5678) If no two courses have a conflict then a total of 2500(50*50) schedules are possible.

These "schedules" (Stored in ArrayLists since the number of user inputs varies from 1-8 and possible number of results varies from 1-100,000. The group of all schedules is a double ArrayList that looks like this ArrayList>. On iOS I use NSMutableArray) are then fed into the intent that is the next Activity. This Activity (Fragment techincally?) will be a pager that allows the user to scroll through the different combinations.

I copied the method of search and sort exactly as it is in iOS(This may not be the right thing to do since the languages and data structures may be fundamentally different) and it works correctly with small output but when it gets too large it can't handle it.

So is multithreading the answer? Should I use something other than a HashMap? Something other than ArrayLists? I only assume multithreading because the errors indicate that too much is being done on the main thread. I've also read that there is a limit to the size of data passed using Intents but I have no idea.

If I was unclear on anything feel free to ask for clarification. Also, I've been doing Android for ~2 weeks so I may completely off track but hopefully not, this is a fully functional and complete app in the iTunes Store already so I don't think I'm that far off. Thanks!

Bryce Langlotz
  • 303
  • 1
  • 4
  • 17
  • for shorting arraylist check this http://stackoverflow.com/questions/4699807/sort-arraylist-of-array-in-java and for passing data from one activity to other u can declare your arraylist in separate class as public static – Jaiprakash Soni Jan 16 '14 at 06:08
  • I don't understand why it is 2500 (50x50) possibilities. If you have two courses with one time slot on the same time then number is already 2 but not 1 (1x1) – Eugen Martynov Jan 16 '14 at 06:10
  • each course has 50 sections so combining 1 from each gives you 2500 possible combinations. Think of 1, 2, 3, ..., 50 and 51, 52, 53, ..., 100. You could have 1 and 51, 1 and 52, 1 and 53,... , 6 and 79,... ,50 and 100 – Bryce Langlotz Jan 16 '14 at 06:19

2 Answers2

1

1) I think you should go with AsynTask of Android .The way it handle the View into `UI

threadandBackground threadfor operations (Like Sorting` ) is sufficient enough to help

you to get the Data Processed into Background thread And on Processing you can get the

Content on UI Thread.

Follow This ShorHand Example for This:

Example to Use Asyntask

2) Example(How to Proceed):

a) define your view into onPreExecute()

b) Do your Background Operation into doInBackground()

c) Get the Result into onPostExceute() and call the content for New Activty

Hope this could help...

Community
  • 1
  • 1
Nitesh Tiwari
  • 4,742
  • 3
  • 28
  • 46
0

I think it's better for you to use TreeMap instead of HashMap, which sorts data automatically everytime you mutate it. Therefore you won't have to sort your data before start another activity, you just pass it and that's all.

Also for using it you have to implement Comparable interface in your class which represents value of Map.

You can also read about TreeMap class there: http://docs.oracle.com/javase/7/docs/api/java/util/TreeMap.html

Autocrab
  • 3,474
  • 1
  • 15
  • 15
  • I may have made a mistake. When I said sort I didn't mean sorting the section data I meant running an algorithm to get sections from the hashmap to compare them, so I'm not changing the data once It's initialized – Bryce Langlotz Jan 16 '14 at 06:25