我正在将图像上传到服务器,并在上传后我正在下载该图像以在屏幕上显示。一切正常,但我有一个问题,当我点击上传后选择它退出应用程序的图像并带我到设备主屏幕,然后上传后再下载到它指向该屏幕,时间取决于图像尺寸。谁能告诉我这是什么问题? 看看我实施的代码:
protected void uploadImageToServer(Bitmap bitmap)
{
//Bitmap yourBitmap;
Bitmap resized = Bitmap.createScaledBitmap(bitmap, 100, 100, true);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
resized.compress(Bitmap.CompressFormat.JPEG, 100, baos);
byte[] b = baos.toByteArray();
String encodedImage = Base64.encodeToString(b, Base64.DEFAULT);
Log.w("encodedImage",encodedImage);
if(isInternetOn(this)){
Log.i("UserID",""+mSettings.get_ID());
btn_Delete_Image.setVisibility(Button.INVISIBLE);
// Toast.makeText(this, "webservice not ready", Toast.LENGTH_LONG).show();
HomeClubTask forgotPaswTask=new HomeClubTask();
forgotPaswTask.execute(mSettings.get_ID(),encodedImage);
}else{
Toast.makeText(this, Constants.NO_NETWORK, Toast.LENGTH_LONG).show();
}
}
private class HomeClubTask extends AsyncTask<String, Void, Object> {
@Override
protected void onPreExecute() {
super.onPreExecute();
dialog = new ProgressDialog(HomeClub.this);
dialog.show();
dialog.setContentView(R.layout.customdialog);
dialog.setIndeterminate(false);
dialog.setCancelable(false);
dialog.setCanceledOnTouchOutside(false);
}
@Override
protected Object doInBackground(String... params) {
return webService.Call(WebServiceCall.UploadUserImage, params);
}
@Override
protected void onPostExecute(Object result) {
super.onPostExecute(result);
if (dialog!=null && dialog.isShowing()){
dialog.cancel();
}
boolean status=false;
String statusMessage="";
String statusId="";
try {
if(result instanceof SoapObject){
SoapObject response = (SoapObject)result;
Log.i("My Response",""+response);
if(!(response.getProperty("Status").toString().equalsIgnoreCase("anyType{}"))){
String value=response.getProperty("Status").toString();
if(value.equalsIgnoreCase("true"))
status=true;
else
status=false;
}
if(!(response.getProperty("StatusMessage").toString().equalsIgnoreCase("anyType{}"))){
statusMessage=response.getProperty("StatusMessage").toString();
}
}
} catch (Exception e) {
Log.w("FileNotFound","Yes");
}
if(checkImageUpload)
{
statusMessage = "Image deleted successfully";
checkImageUpload = false;
}
if(status){
Log.w("Alert_Called","Yes");
new DownloadImageTask(ivUserImage, ivUserImage_L)
.execute(StaticUtils.userImagePath);
showMessageInfo(statusMessage);
rl_mainbody.setVisibility(RelativeLayout.VISIBLE);
}else{
showAlert(HomeClub.this,statusMessage, R.string.OK, null);
rl_mainbody.setVisibility(RelativeLayout.VISIBLE);
}
};
}
private class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
ImageView bmImage;
ImageView bmIv;
public DownloadImageTask(ImageView bmImage, ImageView bmIv) {
this.bmImage = bmImage;
this.bmIv = bmIv;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
}
protected Bitmap doInBackground(String... urls) {
String urldisplay = urls[0];
Bitmap mIcon11 = null;
try {
InputStream in = new java.net.URL(urldisplay).openStream();
BitmapFactory.Options options=new BitmapFactory.Options();
options.inSampleSize = 2;
mIcon11 = BitmapFactory.decodeStream(in,null,options);
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
return mIcon11;
}