I'm sorry for posting similar question to my previous one, but I just can't figure this out.
I've been using simple "ping" example I found here and just wanted to add ProgressBar but with no luck. I really don't understand what's going on.
So, this works fine:
protected void onPreExecute() {
sb = new StringBuilder();
mPOut = new PipedOutputStream();
try {
mPIn = new PipedInputStream(mPOut);
mReader = new LineNumberReader(new InputStreamReader(mPIn));
} catch (IOException e) {
cancel(true);
}
//myBar.setVisibility(View.VISIBLE); -> PROBLEM!!!
}
protected Object doInBackground(Object... arg0) {
try {
process = Runtime.getRuntime().exec("ping -c 4 " + ipadd);
InputStream in = process.getInputStream();
OutputStream out = process.getOutputStream();
byte[] buffer = new byte[1024];
int count;
while ((count = in.read(buffer)) != -1) {
mPOut.write(buffer, 0, count);
String bs= new String(buffer);
publishProgress();
}
in.close();
out.close();
mPOut.close();
mPIn.close();
} catch (IOException e) {
}
return null;
}
protected void onPostExecute(Object result) {
myBar.setVisibility(View.INVISIBLE);
tv.setText(sb);
System.out.println(sb);
}
I get output from ping, myBar is obviously not diplayed since it is invisible in the first place.
If I remove the comment from the line I marked as a problem (set progress bar visibility to visible), I simply get no output from ping. I seems that it somehow messes up my I/O or something. ProgressBar is displayed and hidden at the end, but no output.
I really can't figure this out, so if you have any idea, I would really appreciate any help.
Thanks!!!