mori mori - 4 months ago 9
Android Question

Android app showing black screen while waiting HTTP response

I have been trying to develop an Android app which lets the user take a picture and then send the image over HTTP. I am using the native camera.

After the user takes the picture and hits the save button, I get a black screen while the app sends the info and waits for a response. I would rather display a progressdialog but no matter what I tried, the black screen stays there and the progressdialog can only be seen after getting the response and hitting the back button. I have tried using setContentView() to no avail. The threads are for HTTP request.

Here is the code for the camera start and finish:

protected void startCameraActivity()
{

File file = new File( _path );
Uri out = Uri.fromFile( file );

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE );
intent.putExtra( MediaStore.EXTRA_OUTPUT, out );

startActivityForResult( intent, 0 );
}

protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
switch( resultCode )
{
case 0:
break;

case -1:
m_ProgressDialog = ProgressDialog.show(MainActivity.this, "Please wait...", "Uploading data ...", true, true);
onPhoto();
break;
}
}

protected void onPhoto()
{
taken = true;


PipedOutputStream pos = new PipedOutputStream();
PipedInputStream pis = null;
try {
pis = new PipedInputStream(pos);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Sender sender = new Sender(pos);
Receiver receiver = new Receiver(pis);
sender.start();
receiver.start();
try {
sender.join();
receiver.join();
try {
field.setText(receiver.getIn().readUTF());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

try {
pis.close();
pos.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}

Answer

Check out this link: How can i use Async Task while uploading a file to the server?

In onPreExecute() you can define what you want to show while the image is processing (a progress bar, a spinner...).

Comments