I want to put progress bar when object is sent to the server. But I don't know what the code I need to write in doInBackground() method and what the code in onProgressUpdate() .
Here Client Socket program is used to send Object to the Server.
Code (Inner Class):
class DownloadFileAsync extends AsyncTask<String, String, String> {
@Override
protected void onPreExecute() {
dialog = new ProgressDialog(this);
dialog.setMessage("Uploading...");
dialog.setIndeterminate(false);
dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
dialog.setProgress(0);
dialog.show();
}
@Override
protected String doInBackground(String... aurl) {
}
@Override
protected void onProgressUpdate(String... progress) {
}
@Override
protected void onPostExecute(String unused) {
}
}
So, here what I need to write in doInBackground() and in onProgressUpdate()
I have one object serverObject which I need to send to the Server.
Currently I am using following code to send object to the server without any progress bar:
Socket s = new Socket("xxx.xx.xx.xxx", xxx);
//to send object to the server
ObjectOutputStream oos = new ObjectOutputStream(s.getOutputStream());
oos.writeObject(serverObject);
oos.flush();
if (s != null) {s.close();}
if (oos != null) {oos.close();}
how I write this code into doInBackground() method and keep track up to what % data is send.
How to get the size of the object. In lot of site they mention size of the File. But in my case this is a object.
And one more thing to execute this I need to write :
new DownloadFileAsync().execute(params);
So how I get this params.