AWS s3 TransferUtility из-за ошибки памяти установки индикатора выполнения в Android
Я получаю сообщение об ошибке "Недостаточно памяти" при попытке обновить процент загруженного индикатора выполнения в окне восстановления (обычно между 5-6 файлами). Файлы загружаются и прогресс обновляется с помощью TransferUtility TransferListener.
Я думаю, что это связано с моим кодом, потому что я читаю документацию по AWS TransferUtility, предназначенную для запуска в фоновом режиме.
Это первый раз, когда я неоднократно сталкивался с этой ошибкой, поэтому я хотел бы уловить проблему во время ее возникновения.
Вот как я настроил наблюдателя:
private void setUpDownloadObserverArrayList(){
// Setup an arraylist of transfer observers
transferObserversArrayList = new ArrayList<>();
// For each item in the alarm array add an observer
for (int i=0; i < downloadingAlarmsArrayList.size(); i ++){
// Get the key key from the media location
String key = getKeyFromMediaLocation(downloadingAlarmsArrayList.get(i).getAlarmMediaLocation());
// Create a file
appFolderString = getString(R.string.app_folder_name);
File mediaFile = createMediaFile(appFolderString, alarmPackID, key);
// Create a transfer observer for downloading the individual alarm
TransferObserver transferObserver = createTransferObserver(key, mediaFile);
// Create a transfer listener and add the title alarm being downloaded
TransferListener transferListener = createTransferListener(downloadingAlarmsArrayList.get(i), i);
// Add the transfer listener to the transfer observer
transferObserver.setTransferListener(transferListener);
// Add the transfer observer to the observer arraylist
transferObserversArrayList.add(transferObserver);
}
}
Вот как я настроил слушателя:
TransferListener transferListener = new TransferListener() {
@Override
public void onStateChanged(int id, TransferState state) {
switch (state) {
case COMPLETED:
// Update the local database to signify media downloaded
updateLocalDataBaseAlarmDownloaded(downloadingAlarmPackInfo, true);
break;
case FAILED:
// Update the local database to signify media failed to download
updateLocalDataBaseAlarmDownloaded(downloadingAlarmPackInfo, false);
break;
}
updateDownloadingRecylerview("STATE", arraylistPosition, 0L, 0L, state.toString());
}
@Override
public void onProgressChanged(int id, long bytesCurrent, long bytesTotal) {
updateDownloadingRecylerview("PROGRESS", arraylistPosition,bytesCurrent, bytesTotal,"");
}
@Override
public void onError(int id, Exception ex) {
updateDownloadingRecylerview("EXCEPTION", arraylistPosition, 0L, 0L, "Error" );
}
};
return transferListener;
}
Это метод для обновления recylerview:
private void updateDownloadingRecylerview (String typeOfUpdate, int arrayListPosition, long bytesDownloaded, long bytesTotal, String state){
// Get the Download Info for the arraylist to change
DownloadAlarmInfo downloadAlarmPackInfo = downloadingAlarmsArrayList.get(arrayListPosition);
// Set the value for the dowload arraylist element
switch (typeOfUpdate) {
case "STATE":
if (state.equals("IN_PROGRESS")){
downloadAlarmPackInfo.setDownloadStatus("PAUSE");
} else if (state.equals("COMPLETED")) {
downloadAlarmPackInfo.setDownloadStatus("COMPLETE");
}
break;
case "PROGRESS":
if (bytesTotal != 0L){
// Calculate the percentage downloaded
double ratio = bytesDownloaded / (double) bytesTotal;
DecimalFormat percentFormat= new DecimalFormat("#%");
String percentString = percentFormat.format(ratio);
String percent = percentString.replaceAll("%", "");
downloadAlarmPackInfo.setPercentageDownloaded(Integer.valueOf(percent));
downloadAlarmPackInfo.setTimeToDownload(percentString);
} else {
downloadAlarmPackInfo.setTimeToDownload("0%");
}
break;
case "EXCEPTION":
downloadAlarmPackInfo.setDownloadStatus("Error");
break;
}
// Set the value of the arraylist with the updated data
downloadingAlarmsArrayList.set(arrayListPosition, downloadAlarmPackInfo);
// Update the recylerview
downloadAlarmPacksAdapter.notifyItemChanged(arrayListPosition);
}
Это полная ошибка:
02-21 15:32:06.736 19982-19982/com.fanfare.fanfareapp E/art: Throwing OutOfMemoryError "Failed to allocate a 28 byte allocation with 12 free bytes and 12B until OOM" (recursive case)
02-21 15:32:06.736 19982-20058/com.fanfare.fanfareapp I/art: WaitForGcToComplete blocked for 245.052ms for cause Alloc
02-21 15:32:06.773 19982-19982/com.fanfare.fanfareapp E/art: "main" prio=5 tid=1 Runnable
02-21 15:32:06.773 19982-19982/com.fanfare.fanfareapp E/art: | group="main" sCount=0 dsCount=0 obj=0x743d0000 self=0xb7bbeba8
02-21 15:32:06.773 19982-19982/com.fanfare.fanfareapp E/art: | sysTid=19982 nice=0 cgrp=default sched=0/0 handle=0xb6fc9bec
02-21 15:32:06.773 19982-19982/com.fanfare.fanfareapp E/art: | state=R schedstat=( 14048884038 1042680856 8331 ) utm=1289 stm=115 core=2 HZ=100
02-21 15:32:06.773 19982-19982/com.fanfare.fanfareapp E/art: | stack=0xbe41f000-0xbe421000 stackSize=8MB
02-21 15:32:06.773 19982-19982/com.fanfare.fanfareapp E/art: | held mutexes= "mutator lock"(shared held)
02-21 15:32:06.773 19982-19982/com.fanfare.fanfareapp E/art: native: #00 pc 0000505c /system/lib/libbacktrace_libc++.so (UnwindCurrent::Unwind(unsigned int, ucontext*)+23)
02-21 15:32:06.773 19982-19982/com.fanfare.fanfareapp E/art: native: #01 pc 00003739 /system/lib/libbacktrace_libc++.so (Backtrace::Unwind(unsigned int, ucontext*)+8)
02-21 15:32:06.773 19982-19982/com.fanfare.fanfareapp E/art: native: #02 pc 0024a719 /system/lib/libart.so (art::DumpNativeStack(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, int, char const*, art::mirror::ArtMethod*)+68)
02-21 15:32:06.773 19982-19982/com.fanfare.fanfareapp E/art: native: #03 pc 0022d321 /system/lib/libart.so (art::Thread::DumpStack(std::__1::basic_ostream<char, std::__1::char_traits<char> >&) const+140)
02-21 15:32:06.773 19982-19982/com.fanfare.fanfareapp E/art: native: #04 pc 0023064b /system/lib/libart.so (art::Thread::ThrowOutOfMemoryError(char const*)+254)
02-21 15:32:06.773 19982-19982/com.fanfare.fanfareapp E/art: native: #05 pc 0013d1b9 /system/lib/libart.so (art::gc::Heap::ThrowOutOfMemoryError(art::Thread*, unsigned int, art::gc::AllocatorType)+776)
02-21 15:32:06.773 19982-19982/com.fanfare.fanfareapp E/art: native: #06 pc 0013f603 /system/lib/libart.so (art::gc::Heap::AllocateInternalWithGc(art::Thread*, art::gc::AllocatorType, unsigned int, unsigned int*, unsigned int*, art::mirror::Class**)+1658)
02-21 15:32:06.773 19982-19982/com.fanfare.fanfareapp E/art: native: #07 pc 000f982f /system/lib/libart.so (art::mirror::Class::AllocObject(art::Thread*)+834)
02-21 15:32:06.773 19982-19982/com.fanfare.fanfareapp E/art: native: #08 pc 0022fded /system/lib/libart.so (art::Thread::ThrowNewWrappedException(art::ThrowLocation const&, char const*, char const*)+492)
02-21 15:32:06.773 19982-19982/com.fanfare.fanfareapp E/art: native: #09 pc 002306a3 /system/lib/libart.so (art::Thread::ThrowOutOfMemoryError(char const*)+342)
02-21 15:32:06.773 19982-19982/com.fanfare.fanfareapp E/art: native: #10 pc 0013d1b9 /system/lib/libart.so (art::gc::Heap::ThrowOutOfMemoryError(art::Thread*, unsigned int, art::gc::AllocatorType)+776)
02-21 15:32:06.773 19982-19982/com.fanfare.fanfareapp E/art: native: #11 pc 0013f603 /system/lib/libart.so (art::gc::Heap::AllocateInternalWithGc(art::Thread*, art::gc::AllocatorType, unsigned int, unsigned int*, unsigned int*, art::mirror::Class**)+1658)
02-21 15:32:06.773 19982-19982/com.fanfare.fanfareapp E/art: native: #12 pc 001ed76f /system/lib/libart.so (art::mirror::String::Alloc(art::Thread*, int)+1266)
02-21 15:32:06.773 19982-19982/com.fanfare.fanfareapp E/art: native: #13 pc 001eda85 /system/lib/libart.so (art::mirror::String::AllocFromModifiedUtf8(art::Thread*, char const*)+16)
02-21 15:32:06.773 19982-19982/com.fanfare.fanfareapp E/art: native: #14 pc 0022f5f5 /system/lib/libart.so (art::Thread::InternalStackTraceToStackTraceElementArray(art::ScopedObjectAccessAlreadyRunnable const&, _jobject*, _jobjectArray*, int*)+332)
02-21 15:32:06.773 19982-19982/com.fanfare.fanfareapp E/art: native: #15 pc 001fe673 /system/lib/libart.so (art::VMStack_getThreadStackTrace(_JNIEnv*, _jclass*, _jobject*)+34)
02-21 15:32:06.773 19982-19982/com.fanfare.fanfareapp E/art: native: #16 pc 00000cc9 /system/framework/arm/boot.oat (Java_dalvik_system_VMStack_getThreadStackTrace__Ljava_lang_Thread_2+100)
02-21 15:32:06.773 19982-19982/com.fanfare.fanfareapp E/art: at dalvik.system.VMStack.getThreadStackTrace!(Native method)
02-21 15:32:06.773 19982-19982/com.fanfare.fanfareapp E/art: at java.lang.Thread.getStackTrace(Thread.java:580)
02-21 15:32:06.773 19982-19982/com.fanfare.fanfareapp E/art: at android.os.Debug.getCallers(Debug.java:1675)
02-21 15:32:06.773 19982-19982/com.fanfare.fanfareapp E/art: at android.widget.ProgressBar.setProgress(ProgressBar.java:1316)
02-21 15:32:06.773 19982-19982/com.fanfare.fanfareapp E/art: at android.widget.ProgressBar.setProgress(ProgressBar.java:1311)
02-21 15:32:06.773 19982-19982/com.fanfare.fanfareapp E/art: at com.fanfare.RecyclerViewAdapters.DownloadAlarmPacksAdapter.onBindViewHolder(DownloadAlarmPacksAdapter.java:73)
02-21 15:32:06.773 19982-19982/com.fanfare.fanfareapp E/art: at com.fanfare.RecyclerViewAdapters.DownloadAlarmPacksAdapter.onBindViewHolder(DownloadAlarmPacksAdapter.java:19)
02-21 15:32:06.773 19982-19982/com.fanfare.fanfareapp E/art: at android.support.v7.widget.RecyclerView$Adapter.onBindViewHolder(RecyclerView.java:6354)
02-21 15:32:06.773 19982-19982/com.fanfare.fanfareapp E/art: at android.support.v7.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:6387)
02-21 15:32:06.773 19982-19982/com.fanfare.fanfareapp E/art: at android.support.v7.widget.RecyclerView$Recycler.tryBindViewHolderByDeadline(RecyclerView.java:5343)
02-21 15:32:06.773 19982-19982/com.fanfare.fanfareapp E/art: at android.support.v7.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:5606)
02-21 15:32:06.773 19982-19982/com.fanfare.fanfareapp E/art: at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5448)
02-21 15:32:06.773 19982-19982/com.fanfare.fanfareapp E/art: at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5444)
02-21 15:32:06.773 19982-19982/com.fanfare.fanfareapp E/art: at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2224)
02-21 15:32:06.773 19982-19982/com.fanfare.fanfareapp E/art: at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1551)
02-21 15:32:06.773 19982-19982/com.fanfare.fanfareapp E/art: at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1511)
02-21 15:32:06.773 19982-19982/com.fanfare.fanfareapp E/art: at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:595)
02-21 15:32:06.773 19982-19982/com.fanfare.fanfareapp E/art: at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3600)
02-21 15:32:06.773 19982-19982/com.fanfare.fanfareapp E/art: at android.support.v7.widget.RecyclerView.onMeasure(RecyclerView.java:3036)
02-21 15:32:06.773 19982-19982/com.fanfare.fanfareapp E/art: at android.view.View.measure(View.java:17913)
02-21 15:32:06.773 19982-19982/com.fanfare.fanfareapp E/art: at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5698)
02-21 15:32:06.773 19982-19982/com.fanfare.fanfareapp E/art: at android.widget.FrameLayout.onMeasure(FrameLayout.java:465)
02-21 15:32:06.773 19982-19982/com.fanfare.fanfareapp E/art: at android.view.View.measure(View.java:17913)
02-21 15:32:06.773 19982-19982/com.fanfare.fanfareapp E/art: at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:846)
02-21 15:32:06.773 19982-19982/com.fanfare.fanfareapp E/art: at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:512)
02-21 15:32:06.773 19982-19982/com.fanfare.fanfareapp E/art: at android.view.View.measure(View.java:17913)
02-21 15:32:06.773 19982-19982/com.fanfare.fanfareapp E/art: at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5698)
02-21 15:32:06.773 19982-19982/com.fanfare.fanfareapp E/art: at android.widget.FrameLayout.onMeasure(FrameLayout.java:465)
02-21 15:32:06.773 19982-19982/com.fanfare.fanfareapp E/art: at android.view.View.measure(View.java:17913)
02-21 15:32:06.773 19982-19982/com.fanfare.fanfareapp E/art: at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5698)
02-21 15:32:06.773 19982-19982/com.fanfare.fanfareapp E/art: at android.widget.FrameLayout.onMeasure(FrameLayout.java:465)
02-21 15:32:06.773 19982-19982/com.fanfare.fanfareapp E/art: at android.view.View.measure(View.java:17913)
02-21 15:32:06.773 19982-19982/com.fanfare.fanfareapp E/art: at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5698)
02-21 15:32:06.773 19982-19982/com.fanfare.fanfareapp E/art: at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1692)
02-21 15:32:06.773 19982-19982/com.fanfare.fanfareapp E/art: at android.widget.LinearLayout.measureVertical(LinearLayout.java:760)
02-21 15:32:06.773 19982-19982/com.fanfare.fanfareapp E/art: at android.widget.LinearLayout.onMeasure(LinearLayout.java:629)
02-21 15:32:06.773 19982-19982/com.fanfare.fanfareapp E/art: at android.view.View.measure(View.java:17913)
02-21 15:32:06.773 19982-19982/com.fanfare.fanfareapp E/art: at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5698)
02-21 15:32:06.773 19982-19982/com.fanfare.fanfareapp E/art: at android.widget.FrameLayout.onMeasure(FrameLayout.java:465)
02-21 15:32:06.773 19982-19982/com.fanfare.fanfareapp E/art: at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2730)
02-21 15:32:06.773 19982-19982/com.fanfare.fanfareapp E/art: at android.view.View.measure(View.java:17913)
02-21 15:32:06.773 19982-19982/com.fanfare.fanfareapp E/art: at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2396)
02-21 15:32:06.773 19982-19982/com.fanfare.fanfareapp E/art: at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1404)
02-21 15:32:06.773 19982-19982/com.fanfare.fanfareapp E/art: at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1628)
02-21 15:32:06.773 19982-19982/com.fanfare.fanfareapp E/art: at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1282)
02-21 15:32:06.773 19982-19982/com.fanfare.fanfareapp E/art: at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6720)
02-21 15:32:06.773 19982-19982/com.fanfare.fanfareapp E/art: at android.view.Choreographer$CallbackRecord.run(Choreographer.java:800)
02-21 15:32:06.773 19982-19982/com.fanfare.fanfareapp E/art: at android.view.Choreographer.doCallbacks(Choreographer.java:603)
02-21 15:32:06.773 19982-19982/com.fanfare.fanfareapp E/art: at android.view.Choreographer.doFrame(Choreographer.java:572)
02-21 15:32:06.773 19982-19982/com.fanfare.fanfareapp E/art: at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:786)
02-21 15:32:06.773 19982-19982/com.fanfare.fanfareapp E/art: at android.os.Handler.handleCallback(Handler.java:815)
02-21 15:32:06.773 19982-19982/com.fanfare.fanfareapp E/art: at android.os.Handler.dispatchMessage(Handler.java:104)
02-21 15:32:06.773 19982-19982/com.fanfare.fanfareapp E/art: at android.os.Looper.loop(Looper.java:194)
02-21 15:32:06.773 19982-19982/com.fanfare.fanfareapp E/art: at android.app.ActivityThread.main(ActivityThread.java:5624)
02-21 15:32:06.773 19982-19982/com.fanfare.fanfareapp E/art: at java.lang.reflect.Method.invoke!(Native method)
02-21 15:32:06.773 19982-19982/com.fanfare.fanfareapp E/art: at java.lang.reflect.Method.invoke(Method.java:372)
02-21 15:32:06.773 19982-19982/com.fanfare.fanfareapp E/art: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:959)
02-21 15:32:06.773 19982-19982/com.fanfare.fanfareapp E/art: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754)
Спасибо за вашу помощь