Android AsyncTask在一段时间后没有响应

Android AsyncTask在一段时间后没有响应,android,android-asynctask,android-service,Android,Android Asynctask,Android Service,大家好,我有一个AsyncTask类 public class PostFileProc extends AsyncTask<Void, Void, Void> { @Override protected Void doInBackground(Void... params) { fileName1 = "somefile"; try { FileInputStream fileInputStream = new FileInp

大家好,我有一个AsyncTask类

public class PostFileProc extends AsyncTask<Void, Void, Void>
{
    @Override
    protected Void doInBackground(Void... params) {

    fileName1 = "somefile";


    try {

        FileInputStream fileInputStream = new FileInputStream(new File(
                fileName1));

        URL url = new URL(urlPath);
        connection = (HttpURLConnection) url.openConnection();
        connection.setDoInput(true);
        connection.setDoOutput(true);
        connection.setUseCaches(false);

        // Enable POST method
        connection.setRequestMethod("POST");

        connection.setRequestProperty("Connection", "Keep-Alive");
        connection.setRequestProperty("ENCTYPE", "multipart/form-data");
        connection.setRequestProperty("Content-Type",
                "multipart/form-data;boundary=" + boundary);

        outputStream = new DataOutputStream(connection.getOutputStream());
        outputStream.writeBytes(twoHyphens + boundary + lineEnd);
        outputStream
                .writeBytes("Content-Disposition: form-data; name=\"uploadedfile\";filename=\""
                        + fileName1 + "\"" + lineEnd);
        outputStream.writeBytes(lineEnd);

        bytesAvailable = fileInputStream.available();
        bufferSize = Math.min(bytesAvailable, maxBufferSize);
        buffer = new byte[bufferSize];

        // Read file
        bytesRead = fileInputStream.read(buffer, 0, bufferSize);

        while (bytesRead > 0) {
            outputStream.write(buffer, 0, bufferSize);
            bytesAvailable = fileInputStream.available();
            bufferSize = Math.min(bytesAvailable, maxBufferSize);
            bytesRead = fileInputStream.read(buffer, 0, bufferSize);
        }

        outputStream.writeBytes(lineEnd);
        outputStream.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);

        serverResponseMessage = connection.getResponseMessage();

        fileInputStream.close();
        outputStream.flush();
        outputStream.close();

    }

    catch (Exception ex) {
        ex.getMessage();
    }


    return null;
}
然后,它将运行9-10次成功的来电和来电短信,但在此之后,我的服务得到停止。程序将不再响应。
请有人帮我,是吗

它是否显示任何错误?您是否也可以发布stacktrace?谢谢@Wizard的回复。不,它没有显示任何错误。只有服务才能得到stoped@Wizard,用于在同一进程的AsyncTask中发布Json数据。而且它永远不会停止,但如上图所示发布文件时,它会停止。@user3310056 ok是当服务停止时应用程序关闭
 @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
PostFileProc upFile = new PostFileProc();
                upFile.execute();
}