In this very simple code example, messages get lost every once in a while. What is wrong here?
public class AndroidTesterActivity extends Activity {
private static final int END = 500000;
private static int i = 0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
i=0;
}
@Override
public void onResume()
{
super.onResume();
while(i < END)
{
Log.d("x", ""+i++);
}
Log.e("x", "END");
}
}
For example i get two consecutive log messages 139371 and 140001 … so 630 messages are simply lost, even though i is counted up? How can i be counted without the Log being written?
I have already searched, if someone else already had the same problem, but didn’t find anything.
Thanks for any help
Just a uneducated guess: The Log class doesn’t push everything directly, I think it collects and pushes under some specific conditions. As your loop should go very fast, it might be that in some conditions the log buffer (or what else) might be overwritten before it was flushed.
I would try to make it in a thread and call
sleep()with some ms in between. Maybe you can reproduce this or find a value where this behavior disappears.