[Solved] android while loop alternative


running while loop codes on the main thread freezes the UI, and makes all other processes pause making your app unresponsive use

Threads..

also note that the while loop you are running is running on a default Thread termed as the ui thread so in short run while loops on separate threads..
eg..

new Thread(new Runnable() {

    @Override
    public void run() {
    // Your hard while loop here
    //get whatever you want and update your ui with ui communication methods.
    }
).start();

for ui communicating methods

View.post(new Runnable() {

    @Override
    public void run() {
    // TODO Auto-generated method stub
    Toast.makeText(getActivity(), "updated ui", Toast.LENGTH_LONG).show();
    }
});    

the view could be any views you are updating..
also like @TehCoder said you could use asynctask but asynctask is not meant for long workaflow work there are 3 of them but i can’t recall the last one

solved android while loop alternative