0

I have a code like this running on Android 2.3.3 (Nexus One)

for(i=0; i<1000; i++){
    for(j=0;j<1000;j++){
         do AND calculation
         do XOR calculation
    }
}

Is this too much calculation for android? I went through the debugger and the debugger lost its control after 3 iteration of the first for loop (3000 iteration total)

I am running this on a new thread like this and call this function on main ui thread..

public void startCalculation(ArrayList<data> featA, ArrayList<data> featB){

    newThread= new Thread(new Runnable(){
        public void run(){
            theFunction();
        }
    });
    newThread.start();
}

Thanks in advance...

Jamie Hutton
  • 260
  • 3
  • 13
codereviewanskquestions
  • 13,460
  • 29
  • 98
  • 167

3 Answers3

3

Yeah it seems likely that the process monitor killed your application because it was unresponsive. Keep long running operations off the UI thread.

fleetway76
  • 1,600
  • 9
  • 12
2

Do not do this on UI thread ... use Threads or AsyncTasks for long running operations

EDITed:

for debug use logcat ... just add

Log.d("Some My Tag", "Debuging value of smth is:" + value);

and then read values from Logcat's window in Eclipse

Selvin
  • 6,598
  • 3
  • 37
  • 43
1

You will get a ANR (Application not responding) error if you carry out long running operations on the UI thread. You should do your heavy duty work in background threads.

Community
  • 1
  • 1
thumbmunkeys
  • 20,606
  • 8
  • 62
  • 110
  • you didnt say in your original question that you run it in a thread... what happens inside of your loop then, are you doing memory intensive things? – thumbmunkeys May 25 '11 at 15:39