Reputation: 9926
I wrote application that contain 2 activities. In the first one - i need to give the user the option to choose image from the gallery and i send this image to some server. The Server return some result - and if the result is OK i need to show the second activity.
The problem that i have ..
when sending the image - i see that the screen is become black ... I want to avoid this and show some nice GUI of 'please wait' - how can i do it ?
i want to make this sending image to the server to be from other thread - how can i do it from android ? how to define new thread with callback that will be called when the thread is done ?
Thanks for any help.
Upvotes: 0
Views: 523
Reputation: 173
Use an asynctask. It would go something like this:
public void sendImage() {
SendToServer.execute();
}
protected class SendToServer extends AsyncTask<Void, Boolean, Void>
{
@Override
protected void onPreExecute()
{
//display your dialog
}
@Override
protected Boolean doInBackground(Void... arg0) {
//code to send your image to the serve
}
@Override
protected void onPostExecute (Boolean updateSuccess)
{
//close your dialog
//If image was successfully sent open your other activity
}
}
Upvotes: 2
Reputation: 12900
This question has an answer which addresses the problem. Use that answer as a start, and let us know if you have any problems with some specific part.
Download image for imageview on Android
Good luck
Upvotes: 1
Reputation: 157457
you can define your custom layout and use the Activity.setContentView method to put whatever you want in your GUI. For instance you can put a ProgressBar widget.
As you have noticed, you wrote your android app in Java SE. Thread are fully supported.
Upvotes: 1
Reputation: 5183
For question number 1:
You should use a ProgressDialog
or a ProgressBar
in order to show to the user that an operation is being executed. For more information you can check here: http://developer.android.com/reference/android/app/ProgressDialog.html
For question number 2:
A good solution would be to use AsyncTask
for this operation which gives you a set of callback functions to control the operation. For more information you can check here: http://developer.android.com/reference/android/os/AsyncTask.html
Hope this helps for now!
Upvotes: 1