2017-02-11 58 views
0

我有一個稍微令人費解的問題,我認爲這將是一個簡單的修復,由於愚蠢的疏忽。意圖服務突然停止

我的主要任務是將圖像和錄音文件上傳到我的服務器上的位置。我通過FTP來做這件事。

  1. 活動通過startService(intentName)調用服務;
  2. onHandleIntent()創建一個新的線程。
  3. 在新線程中,需要上傳的文件被放入ListArray中
  4. 循環遍歷listArray。在此循環中,將文件名傳遞給FTP服務器。如果成功添加,我將此文件名添加到包含已確認名稱文件的另一個ListArray。
  5. 循環完成後,我通過調用stopSelf()來停止服務
  6. 我創建了一個通知來通知用戶服務已完成。

我遇到了第4步的問題。 循環只上傳兩個文件,然後突然停止。當第二個文件上傳時,手機進入睡眠模式。沒有通知。

我曾嘗試以下

  • 我最初使用的AsyncTask但從未成功上傳的所有列出的文件一氣呵成。
  • 使用了StrictMode。
  • 創建了一個服務而不是IntentService的第二個類。
  • 嘗試startForeground() - 但是這不是一個選項,因爲這會殺死我的用戶界面,我得到的應用程序沒有響應彈出。

有人可以建議一種方式嗎? 這裏是我的代碼

這是MainActivity.class

Intent service = new Intent(getApplicationContext(), UploadMedia.class); 
    service.putExtra("imageFileName", "/Folder/uploadtheseimagefiles.txt"); 
    service.putExtra("audioFileName", "/Folder/uploadtheseaudiofiles.txt"); 
    startService(service); 

代碼這裏是我的IntentService

protected void onHandleIntent(Intent intent) { 
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); 
    StrictMode.setThreadPolicy(policy); 

    final String imageFileName = intent.getStringExtra("imageFileName"); 
    final String audioFileName = intent.getStringExtra("audioFileName"); 

    new Thread(new Runnable() { 
     @Override 
     public void run() { 
      String serverAddress = "server address here"; 
      String userID = "user name here"; 
      String password = "password here"; 
      ArrayList<String> confirmed = new ArrayList<String>(); 

      //1. Upload the image files 
      if (imageFileName.length() != 0) { 
       File uploadContents = new File(imageFileName); 
       if (uploadContents.exists()) { 
        try { 
         //Read the entries to be uploaded 
         InputStream ststr = new FileInputStream(uploadContents); 
         BufferedReader stbr = new BufferedReader(new InputStreamReader(ststr)); 
         String line = ""; 
         upData.clear(); 
         while ((line = stbr.readLine()) != null) { 
          upData.add(line.trim()); 
         } 
         stbr.close(); 
         ststr.close(); 

         //Upload the entries 
         confirmed.clear(); 
         for(int i = 0; i < upData.size(); i++) { 
          if (new UploadViaFTP().ftpUpload(upData.get(i).toString(), serverAddress, userID, password)) { 
           confirmed.add(upData.get(i).toString()); 
          } 
         } 

         //Check the uploaded filenames against the ones that were to be uploaded. 
         ArrayList<String> remaining = new ArrayList<String>(); 
         for (int i = 0; i < upData.size(); i++) { 
          if (!confirmed.contains(upData.get(i))) 
           remaining.add(upData.get(i)); 
         } 

         //If there are any remaining, write them back into the file. 
         if (remaining.size() != 0) { 
          try { 
           FileWriter fw = new FileWriter(imageFileName); 
           for (int i = 0; i < remaining.size(); i++) { 
            fw.write(remaining.get(i)); 
            fw.append("\n"); 
           } 
           fw.close(); 
          } catch (IOException e) { 
           // TODO Auto-generated catch block 
           e.printStackTrace(); 
          } 

         } else { //All files have been uploaded 
          File delFile = new File(imageFileName); 
          if (delFile.exists()) 
           delFile.delete(); 
         } 
        } catch (FileNotFoundException e) { 
         // TODO Auto-generated catch block 
         e.printStackTrace(); 
        } catch (IOException e) { 
         // TODO Auto-generated catch block 
         e.printStackTrace(); 
        } 
       } 
      } 

      //2. Upload the audio files 
      if (audioFileName.length() != 0) { 
       File uploadContents = new File(audioFileName); 
       if (uploadContents.exists()) { 
        try { 
         //Read the entries to be uploaded 
         InputStream ststr = new FileInputStream(uploadContents); 
         BufferedReader stbr = new BufferedReader(new InputStreamReader(ststr)); 
         String line = ""; 
         upData.clear(); 
         while ((line = stbr.readLine()) != null) { 
          upData.add(line.trim()); 
         } 
         stbr.close(); 
         ststr.close(); 

         //Upload the entries 
         confirmed.clear(); 
         for(int i = 0; i < upData.size(); i++) { 
          if (new UploadViaFTP().ftpUpload(upData.get(i).toString(), serverAddress, userID, password)) { 
           confirmed.add(upData.get(i).toString()); 
          } 
         } 

         //Check the uploaded filenames against the ones that were to be uploaded. 
         ArrayList<String> remaining = new ArrayList<String>(); 
         for (int i = 0; i < upData.size(); i++) { 
          if (!confirmed.contains(upData.get(i))) 
           remaining.add(upData.get(i)); 
         } 

         //If there are any remaining, write them back into the file. 
         if (remaining.size() != 0) { 
          try { 
           FileWriter fw = new FileWriter(audioFileName); 
           for (int i = 0; i < remaining.size(); i++) { 
            fw.write(remaining.get(i)); 
            fw.append("\n"); 
           } 
           fw.close(); 
          } catch (IOException e) { 
           // TODO Auto-generated catch block 
           e.printStackTrace(); 
          } 

         } else { //All files have been uploaded 
          File delFile = new File(audioFileName); 
          if (delFile.exists()) 
           delFile.delete(); 
         } 
        } catch (FileNotFoundException e) { 
         // TODO Auto-generated catch block 
         e.printStackTrace(); 
        } catch (IOException e) { 
         // TODO Auto-generated catch block 
         e.printStackTrace(); 
        } 
       } 
      } 

      stopSelf(); 

      //Final check before notification. 
      File checkFile = new File("/Folder/uploadtheseimagefiles.txt"); 
      if (!checkFile.exists()) { 
       checkFile = new File("/Folder/uploadtheseaudiofiles.txt"); 
       if (!checkFile.exists()) { 
        NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext()) 
         .setSmallIcon(R.drawable.ic_launcher) 
         .setContentTitle("Something") 
         .setContentText("Uploading of media complete."); 
        Intent notificationIntent = new Intent(getApplicationContext(), MainActivity.class); 
        PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(), 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); 
        builder.setContentIntent(contentIntent); 

        // Add as notification 
        NotificationManager manager = (NotificationManager) getSystemService(getApplication().NOTIFICATION_SERVICE); 
        manager.notify(0, builder.build()); 
       } 
      }    
     } 
    }).start(); 
} 

Manifest.xml文件

<service 
     android:name=".UploadMedia" 
     android:exported="true" 
     android:enabled="true"/> 

代碼新信息: 失敗總是在第二時間發生根據我的測試案例的ond文件。第一幅圖像大小約爲900KB,第二幅圖像大小約爲2MB。 在調試時,我無法獲得第二個文件的FTPUpload的狀態。但是調試器停止了第一個文件,我可以繼續。

新信息:第2部分: 這可能是相關的。我正在使用asynctask將一些數據更新到服務器上的數據庫。一旦成功返回,它會整理所有需要上傳的文件名稱。這個整理的數據就是我通過我的Intent傳遞給服務的數據。

也是另一個供認。我有這個確切的過程運行,並在我的另一個應用程序工作。使用asynctask將數據上傳到數據庫。在執行後的方法中,它調用服務將數據上傳到FTP服務器。我已經將清單文件,服務和對服務的調用進行了比較,所有內容似乎都是一樣的。

新信息:3部分: 日誌文件

02-12 10:03:40.521: I/PERSONAL(14962): Calling the service 
02-12 10:03:40.525: W/Binder_1(791): type=1400 audit(0.0:20440): avc: denied { ioctl } for path="socket:[743779]" dev="sockfs" ino=743779 ioctlcmd=7704 scontext=u:r:system_server:s0 tcontext=u:r:system_server:s0 tclass=unix_stream_socket permissive=0 
02-12 10:03:40.525: W/Binder_1(791): type=1400 audit(0.0:20441): avc: denied { ioctl } for path="socket:[743779]" dev="sockfs" ino=743779 ioctlcmd=7704 scontext=u:r:system_server:s0 tcontext=u:r:system_server:s0 tclass=unix_stream_socket permissive=0 
02-12 10:03:40.534: I/PERSONAL(14962): Uploading audio file 0 
02-12 10:03:40.585: V/RenderScript(14962): 0xb397e000 Launching thread(s), CPUs 4 
02-12 10:03:42.278: I/Finsky(14117): [3310] com.google.android.finsky.d.e.run(1151): Replicating app states via AMAS. 
02-12 10:03:42.398: I/Finsky(14117): [3310] com.google.android.finsky.d.c.a(313): Completed 0 account content syncs with 0 successful. 
02-12 10:03:42.400: I/Finsky(14117): [1] com.google.android.finsky.services.j.a(148): Installation state replication succeeded. 
02-12 10:03:42.434: I/PERSONAL(14962): Uploading audio file 1 
02-12 10:03:42.515: W/Binder_F(1876): type=1400 audit(0.0:20442): avc: denied { ioctl } for path="socket:[743796]" dev="sockfs" ino=743796 ioctlcmd=7704 scontext=u:r:system_server:s0 tcontext=u:r:system_server:s0 tclass=unix_stream_socket permissive=0 
02-12 10:03:42.515: W/Binder_F(1876): type=1400 audit(0.0:20443): avc: denied { ioctl } for path="socket:[743796]" dev="sockfs" ino=743796 ioctlcmd=7704 scontext=u:r:system_server:s0 tcontext=u:r:system_server:s0 tclass=unix_stream_socket permissive=0 
02-12 10:03:43.400: D/audio_hw_primary(201): disable_audio_route: reset and update mixer path: low-latency-playback 
02-12 10:03:43.400: D/audio_hw_primary(201): disable_snd_device: snd_device(2: speaker) 
02-12 10:03:44.222: I/PERSONAL(14962): Uploading image file 0 
02-12 10:03:44.565: W/Binder_5(1372): type=1400 audit(0.0:20444): avc: denied { ioctl } for path="socket:[745643]" dev="sockfs" ino=745643 ioctlcmd=7704 scontext=u:r:system_server:s0 tcontext=u:r:system_server:s0 tclass=unix_stream_socket permissive=0 
02-12 10:03:44.565: W/Binder_5(1372): type=1400 audit(0.0:20445): avc: denied { ioctl } for path="socket:[745643]" dev="sockfs" ino=745643 ioctlcmd=7704 scontext=u:r:system_server:s0 tcontext=u:r:system_server:s0 tclass=unix_stream_socket permissive=0 
02-12 10:03:46.535: W/Binder_4(1220): type=1400 audit(0.0:20446): avc: denied { ioctl } for path="socket:[745654]" dev="sockfs" ino=745654 ioctlcmd=7704 scontext=u:r:system_server:s0 tcontext=u:r:system_server:s0 tclass=unix_stream_socket permissive=0 
02-12 10:03:46.535: W/Binder_4(1220): type=1400 audit(0.0:20447): avc: denied { ioctl } for path="socket:[745654]" dev="sockfs" ino=745654 ioctlcmd=7704 scontext=u:r:system_server:s0 tcontext=u:r:system_server:s0 tclass=unix_stream_socket permissive=0 
02-12 10:03:59.995: W/Binder_6(1388): type=1400 audit(0.0:20448): avc: denied { ioctl } for path="socket:[743809]" dev="sockfs" ino=743809 ioctlcmd=7704 scontext=u:r:system_server:s0 tcontext=u:r:system_server:s0 tclass=unix_stream_socket permissive=0 
02-12 10:03:59.995: W/Binder_6(1388): type=1400 audit(0.0:20449): avc: denied { ioctl } for path="socket:[743809]" dev="sockfs" ino=743809 ioctlcmd=7704 scontext=u:r:system_server:s0 tcontext=u:r:system_server:s0 tclass=unix_stream_socket permissive=0 
02-12 10:04:04.787: I/DeviceStateChecker(1718): screenOn: true, isCharging: true 
02-12 10:04:29.560: D/NetlinkSocketObserver(781): NeighborEvent{elapsedMs=152656259, fe80::86c9:b2ff:fe6c:5ce9, [84C9B26C5CE9], RTM_NEWNEIGH, NUD_PROBE} 
02-12 10:04:29.705: I/PlayCommon(14117): [3292] com.google.android.play.a.g.e(909): Preparing logs for uploading 
02-12 10:04:29.733: I/PlayCommon(14117): [3292] com.google.android.play.a.g.a(1049): Connecting to server: https://play.googleapis.com/play/log?format=raw&proto_v2=true 
02-12 10:04:29.901: I/PERSONAL(14962): Uploading image file 1 
02-12 10:04:29.971: I/PlayCommon(14117): [3315] com.google.android.play.a.g.e(909): Preparing logs for uploading 
02-12 10:04:29.972: I/PlayCommon(14117): [3315] com.google.android.play.a.g.e(911): No file ready to send 
02-12 10:04:31.635: I/PlayCommon(14117): [3292] com.google.android.play.a.g.a(1127): Successfully uploaded logs. 
02-12 10:04:46.450: D/NetlinkSocketObserver(781): NeighborEvent{elapsedMs=152673149, fe80::86c9:b2ff:fe6c:5ce9, [84C9B26C5CE9], RTM_NEWNEIGH, NUD_STALE} 
02-12 10:04:58.348: V/GsmInboundSmsHandler(1549): Unable to find carrier package: [], nor systemPackages: [] 
02-12 10:04:58.363: D/MmsService(1549): getAutoPersisting 
02-12 10:04:58.377: I/ActivityManager(781): Start proc 15147:com.google.android.talk/u0a27 for broadcast com.google.android.talk/com.google.android.apps.hangouts.sms.SmsDeliverReceiver 
02-12 10:04:59.064: D/BabelGcmRegistration(15147): GcmRegistration: Checking GCM registration 
02-12 10:04:59.079: I/Babel_telephony(15147): TeleModule.onApplicationCreate 
02-12 10:04:59.089: I/Babel_SMS(15147): MmsConfig: mnc/mcc: 404/86 
02-12 10:04:59.090: I/Babel_SMS(15147): MmsConfig.loadMmsSettings 
02-12 10:04:59.091: I/Babel_SMS(15147): MmsConfig.loadDeviceMmsSettings from API: userAgent=Nexus5, uaProfUrl=http://gsm.lge.com/html/gsm/Nexus5-M3.xml 
02-12 10:04:59.091: I/Babel_SMS(15147): MmsConfig.loadFromDatabase 
02-12 10:04:59.105: E/SQLiteLog(15147): (1) no such table: mmsconfig 
02-12 10:04:59.107: I/Babel_SMS(15147): MmsConfig: no mmsconfig table android.database.sqlite.SQLiteException: no such table: mmsconfig (code 1): , while compiling: SELECT key, value, type FROM mmsconfig WHERE numeric=? 
02-12 10:04:59.107: I/Babel_SMS(15147): MmsConfig.loadFromResources 
02-12 10:04:59.118: I/Babel_Prime(15147): wrapCrashReportingIntoUncaughtExceptionHandler 
02-12 10:04:59.119: E/Babel_SMS(15147): canonicalizeMccMnc: invalid mccmnc nullnull 
02-12 10:04:59.121: I/Babel_SMS(15147): MmsConfig.loadMmsSettings: userAgent=Nexus5, uaProfUrl=http://gsm.lge.com/html/gsm/Nexus5-M3.xml 
02-12 10:04:59.126: I/Babel_App(15147): Startup - clean 
02-12 10:04:59.128: I/Babel_SMS(15147): ApnsOta: OTA version -1 
02-12 10:04:59.134: I/Babel(15147): Invalid account: 3 isEmptyName: true nameEqualsGaiaId: false 
02-12 10:04:59.169: I/Babel_Prime(15147): isMemoryEnabled=false 
02-12 10:04:59.169: I/Babel_Prime(15147): isTimerEnabled=false 
02-12 10:04:59.169: I/Babel_Prime(15147): isCrashCounterEnabled=true 
02-12 10:04:59.170: I/Babel_Prime(15147): primesPackageConfigurationsProvider=false 
02-12 10:04:59.172: I/Babel(15147): Deleting: false for 3 
02-12 10:04:59.174: I/Babel_Prime(15147): startMemoryMonitor 
02-12 10:04:59.233: D/Babel(15147): created account [email protected] => Redacted-20-chars 
02-12 10:04:59.263: W/FortumoInApp(5700): Broadcast is disabled, there is no sense, to countinue. 
02-12 10:04:59.274: I/Babel_ConcService(15147): Binding ConcurrentService 
02-12 10:04:59.280: I/ActivityManager(781): Killing 13354:com.android.settings/1000 (adj 15): empty #17 
02-12 10:04:59.341: D/ActivityManager(781): cleanUpApplicationRecord -- 13354 
02-12 10:04:59.367: I/Babel_ConcService(15147): Acquired partial wake lock to keep ConcurrentService alive 
02-12 10:04:59.514: W/IcingInternalCorpora(1644): getNumBytesRead when not calculated. 
02-12 10:04:59.518: I/Icing(1644): Usage reports 0 indexed 0 rejected 0 imm upload false 
02-12 10:04:59.672: W/linker(15147): /data/app/com.google.android.gms-2/lib/arm/libgmscore.so: unused DT entry: type 0x7ffffffd arg 0x795 
02-12 10:04:59.689: W/linker(15147): /data/app/com.google.android.gms-2/lib/arm/libconscrypt_gmscore_jni.so: unused DT entry: type 0x1d arg 0xe0 
02-12 10:04:59.689: W/linker(15147): /data/app/com.google.android.gms-2/lib/arm/libconscrypt_gmscore_jni.so: unused DT entry: type 0x7ffffffd arg 0x1cb 
02-12 10:04:59.697: V/JNIHelp(15147): Registering com/google/android/gms/org/conscrypt/NativeCrypto's 242 native methods... 
02-12 10:04:59.712: I/art(15147): Rejecting re-init on previously-failed class java.lang.Class<com.google.android.gms.org.conscrypt.OpenSSLExtendedSessionImpl> 
02-12 10:04:59.713: I/art(15147): Rejecting re-init on previously-failed class java.lang.Class<com.google.android.gms.org.conscrypt.OpenSSLExtendedSessionImpl> 
02-12 10:04:59.768: I/ProviderInstaller(15147): Installed default security provider GmsCore_OpenSSL 
02-12 10:04:59.823: W/VideoCapabilities(15147): Unrecognized profile 2130706433 for video/avc 
02-12 10:04:59.848: I/VideoCapabilities(15147): Unsupported profile 4 for video/mp4v-es 
02-12 10:04:59.858: W/VideoCapabilities(15147): Unrecognized profile 2130706433 for video/avc 
02-12 10:04:59.859: W/VideoCapabilities(15147): Unrecognized profile 2130706433 for video/avc 
02-12 10:04:59.862: W/VideoCapabilities(15147): Unrecognized profile 2130706433 for video/avc 
02-12 10:04:59.927: D/NuPlayerDriver(201): reset(0xb3876600) 
02-12 10:04:59.927: D/NuPlayerDriver(201): notifyListener_l(0xb3876600), (8, 0, 0) 
02-12 10:04:59.927: D/NuPlayerDriver(201): notifyResetComplete(0xb3876600) 
02-12 10:04:59.942: I/Babel_ConcService(15147): Released partial wake lock as ConcurrentService became idle 
02-12 10:05:00.041: D/NuPlayerDriver(201): notifyListener_l(0xb34b8720), (1, 0, 0) 
02-12 10:05:00.041: D/MediaPlayer(921): setSubtitleAnchor in MediaPlayer 
02-12 10:05:00.044: I/MediaFocusControl(781): AudioFocus requestAudioFocus() from [email protected] req=3flags=0x0 
02-12 10:05:00.045: D/NuPlayerDriver(201): start(0xb34b8720), state is 4, eos is 0 
02-12 10:05:00.045: I/GenericSource(201): start 
02-12 10:05:00.053: E/OMXNodeInstance(201): setConfig(103:google.vorbis.decoder, ConfigPriority(0x6f800002)) ERROR: Undefined(0x80001001) 
02-12 10:05:00.053: I/ACodec(201): codec does not support config priority (err -2147483648) 
02-12 10:05:00.054: I/MediaCodec(201): MediaCodec will operate in async mode 
02-12 10:05:00.060: D/Babel_RtcImpressions(15147): Type: 1926 
02-12 10:05:00.072: D/PhoneStatusBar(921): disable: < expand ICONS* alerts SYSTEM_INFO* back home recent clock search quick_settings > 
02-12 10:05:00.075: D/audio_hw_primary(201): out_set_parameters: enter: usecase(1: low-latency-playback) kvpairs: routing=2 
02-12 10:05:00.087: D/NuPlayerDriver(201): notifyListener_l(0xb34b8720), (6, 0, 0) 
02-12 10:05:00.096: D/audio_hw_primary(201): select_devices: out_snd_device(2: speaker) in_snd_device(0: none) 
02-12 10:05:00.096: D/msm8974_platform(201): platform_send_audio_calibration: sending audio calibration for snd_device(2) acdb_id(15) 
02-12 10:05:00.096: D/audio_hw_primary(201): enable_snd_device: snd_device(2: speaker) 
02-12 10:05:00.099: D/audio_hw_primary(201): enable_audio_route: apply and update mixer path: low-latency-playback 
02-12 10:05:00.122: D/CountryDetector(781): The first listener is added 
02-12 10:05:00.639: I/Babel(15147): connection state changed from UNKNOWN to CONNECTED 
02-12 10:05:00.869: I/NuPlayerDecoder(201): [audio] saw output EOS 
02-12 10:05:01.271: D/NuPlayerDriver(201): notifyListener_l(0xb34b8720), (2, 0, 0) 
02-12 10:05:01.271: I/MediaFocusControl(781): AudioFocus abandonAudioFocus() from [email protected] 
02-12 10:05:04.252: D/audio_hw_primary(201): disable_audio_route: reset and update mixer path: low-latency-playback 
02-12 10:05:04.253: D/audio_hw_primary(201): disable_snd_device: snd_device(2: speaker) 
02-12 10:05:04.883: W/IcingInternalCorpora(1644): getNumBytesRead when not calculated. 
02-12 10:05:04.915: I/Icing(1644): Usage reports 0 indexed 0 rejected 0 imm upload false 
02-12 10:05:05.932: I/Icing(1644): Indexing D2350FC178F0C3C6D9357237E165CCBC64772E44 from com.google.android.gms 
02-12 10:05:06.040: I/Icing(1644): Indexing done D2350FC178F0C3C6D9357237E165CCBC64772E44 
02-12 10:05:06.057: D/PhoneStatusBar(921): disable: < expand icons* alerts system_info* back home recent clock search quick_settings > 
02-12 10:05:14.171: I/Babel_ConcService(15147): Acquired partial wake lock to keep ConcurrentService alive 
02-12 10:05:14.182: I/Babel_ConcService(15147): Released partial wake lock as ConcurrentService became idle 
02-12 10:05:18.751: I/ProcessStatsService(781): Prepared write state in 3ms 
02-12 10:05:18.753: I/ProcessStatsService(781): Prepared write state in 2ms 
02-12 10:05:29.137: I/Telecom(781): PhoneAccountRegistrar: SimCallManager queried, returning: null 
02-12 10:05:29.143: I/Babel_telephony(15147): TeleModule.updateConnectionManagerRegistration, registration preference changed from false to false 
02-12 10:05:29.143: W/Babel(15147): BAM#gBA: invalid account id: -1 
02-12 10:05:29.144: W/Babel(15147): BAM#gBA: invalid account id: -1 
02-12 10:05:29.144: I/Babel_telephony(15147): TeleModule.updateIncomingCallRegistration, preferred account for incoming calls changed from: null to null 
02-12 10:05:29.151: I/Telecom(781): PhoneAccountRegistrar: SimCallManager queried, returning: null 
02-12 10:05:49.090: I/PowerManagerService(781): Going to sleep due to screen timeout (uid 1000)... 
02-12 10:05:49.175: W/Binder_3(958): type=1400 audit(0.0:20450): avc: denied { ioctl } for path="socket:[743742]" dev="sockfs" ino=743742 ioctlcmd=7704 scontext=u:r:system_server:s0 tcontext=u:r:system_server:s0 tclass=unix_stream_socket permissive=0 
02-12 10:05:49.175: W/Binder_3(958): type=1400 audit(0.0:20451): avc: denied { ioctl } for path="socket:[743742]" dev="sockfs" ino=743742 ioctlcmd=7704 scontext=u:r:system_server:s0 tcontext=u:r:system_server:s0 tclass=unix_stream_socket permissive=0 
02-12 10:05:49.091: I/PowerManagerService(781): Sleeping (uid 1000)... 
02-12 10:05:49.665: V/KeyguardServiceDelegate(781): onScreenTurnedOff() 

我會採取任何建議/問題。

回答

0

爲什麼要在onHandleIndent中創建一個新線程?這種方法已經從後臺線程調用,因此它已經不會妨礙你的UI渲染或什麼。只需在onHandleIntent方法中直接運行您的邏輯即可。試一試

+0

謝謝Dibzmania。我想知道爲什麼我不這樣做,並根據您的建議更改我的代碼。然而,執行後我意識到了爲什麼我得到了android.View.WindowLeaked錯誤。添加到我的問題結尾的信息。 – Prem

+0

經過大量更改後,您提到的更改的行爲對輸出沒有任何影響。仍然只有前兩個文件正在上傳。接下來你會提出什麼建議? – Prem

+0

你在logcat上得到了什麼?當你說它突然停止時,應該有一些日誌。你確定上傳過程沒有問題嗎?不管你得到什麼樣的結果,你都不應該在意向服務 – Dibzmania

0

您不需要調用stopSelf(),因爲IntentService在隊列中沒有請求服務時會自行停止。

添加更多日誌語句,以瞭解在上傳所有文件之前爲何要停止自己。