Reputation: 1
I am making an app that sends an image to a server but the reception client might have a have problem. Logcat shows The application may be doing too much work on its main thread
. I don't know how to resolve this. Here is my code
onCreate
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
imageView = (ImageView) findViewById(R.id.IV);
BitmapImage.execute((Runnable)imageView);
}
Receiving Image and show
public class BitmapImage extends AsyncTask<Object, Void, Bitmap> {
private ImageView bmImage;
DataInputStream dis;
OutputStream fos;
int len;
int size = 8012;
byte[] data = new byte[size];
@Override
protected Bitmap doInBackground(Object... params) {
Bitmap size = null;
Bitmap mBitmap = null;
bmImage = (ImageView)params[0];
try {
Log.d("TCP", "C: Connecting...");
Socket server = new Socket(IPN, 2965);
fName = "img.TIFF";
try {
PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(server.getOutputStream())), true);
out.println(command);
dirPath = getFilesDir().getAbsolutePath();
File filepath = new File(dirPath);
if (!filepath.isDirectory()) {
filepath.mkdirs();
Log.i("tag", "디렉토리 생성");
}
Log.i("tag", "m : " + "파일 생성");
dis = new DataInputStream(server.getInputStream());
rf = new File(filepath + "/" + fName);
fos = openFileOutput(fName, Context.MODE_PRIVATE);
while ((len = dis.read(data)) != -1) {
fos.write(data, 0, len);
Log.i("tag", "tag : " + "수신중");
}
Log.i("tag", "tag : " + "수신 완료");
} catch (Exception e) {
Log.e("tag", "err : " + e);
e.printStackTrace();
} finally {
fos.flush();
fos.close();
dis.close();
}
} catch (Exception e) {
Log.e("TCP", "C: Error", e);
}
try {
ParcelFileDescriptor pfd = getContentResolver().openFileDescriptor(Uri.fromFile(rf), "r");
mBitmap = BitmapFactory.decodeFileDescriptor(pfd.getFileDescriptor());
size = Bitmap.createScaledBitmap(mBitmap, (S*mBitmap.getWidth()), (S*mBitmap.getHeight()), true);
Log.i("tag", "출력 완료");
} catch (Exception e) {
Log.e("tag", "오류났당 -> " + e);
}
return size;
}
@Override
protected void onPostExecute(Bitmap bitmap) {
super.onPostExecute(bitmap);
bmImage.setImageBitmap(bitmap);
}
}
I thought the size of the file is the problem so I changed the file format but it did not solve this. Disunite receiving portion and an output portion. That also can't solve this.
Finally I want received some second application, and I will use android remote PC.
Upvotes: 0
Views: 71
Reputation: 5269
add this line in manifest under the application
<application
android:largeHeap="true" >
</application>
it will help to solve memory problem while loading images.
Upvotes: 1