Showing posts with label asynchronous. Show all posts
Showing posts with label asynchronous. Show all posts

Android - Check internet access / InetAddress never timeouts

I got a AsyncTask that is supposed to check the network access to a host name. But the doInBackground is never timed out. Anyone have a clue?public class HostAvailabilityTask extends AsyncTask<String, Void, Boolean>{

private Main main;

public HostAvailabilityTask(Main main){
this.main = main;
}

protected Boolean doInBackground(String... params) {
Main.Log("doInBackground() isHostAvailable():"+params[0]);

try {
return InetAddress.getByName(params[0]).isReachable(30);
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return false;
}

protected void onPostExecute(Boolean... result) {
Main.Log("onPostExecute()");

if(result[0] == false){
main.setContentView(R.layout.splash);
return;
}

main.continueAfterHostCheck();
}

}

Android - Suggestions for writing manageable asynchronous code

I have recently written my first Android app which was roughly 8,000-10,000 lines of code. One thing that continuously hindered my use of normal design patterns was android's heavy use of asynchronous calls (opening dialogs, activities, etc). Due to this, my code very quickly began looking "spaghetti" like, and I eventually started to dislike looking at certain classes.

Are there specific design patterns or programming methodologies which are for systems such as these that anyone would recommend? Are there any suggestions for writing manageable asynchronous code?

Popular Posts