Simple SSH connect with JSch

You have to execute that code in another thread so you don’t hang the UI thread is what that exception means. If the UI thread is executing a network call it can’t repaint the UI so your users sees a frozen UI that doesn’t respond to them while the app is waiting on the network call to finish. Android wants to avoid bad user experiences like this so it prevents you from doing things like this by throwing this exception.

Your onCreate() method should invoke another thread (I’d suggest using an AsyncTask over a raw thread) to perform the SSH connection. Then when it’s done it can post the results back to the UI thread and safely update your application’s UI from the UI thread.

http://developer.android.com/reference/android/os/AsyncTask.html

Leave a Comment