You don't need to call the Looper.prepare();
and Looper.loop();
. You can use AsyncTask to do the upload task in a worker thread. Like this:
class UploadTask extends AsyncTask<String, Object, Object> {
@Override
protected Object doInBackground(String... content) {
uploadFile(content[0]);
return null;
}
}
And in the service:
public int onStartCommand(Intent intent, int flags, int startId) {
imagepath = Environment.getExternalStorageDirectory().toString() + "/downloadedfile1.jpg";
new UploadTask().execute(imagepath, null, null);
}
PS: You can refer to this to get yourself familiar with Looper and Handler stuff.