我Activity
创建了一个AsyncTask
从文件加载数据并更新onProgressUpdate()
经典书籍的 UI AsyncTask
。但是 Android 是在 Activity 启动后
立即放置的。 onPause()
AsyncTask
我试图理解为什么(以及如何防止它)
这会导致所有AsyncTask
UI 更新停止;然后,当AsyncTask
完成时,它Activity
不会自行恢复,我必须触摸屏幕或按一些操作栏按钮才能让它onResume()
编辑:
这是 logcat,(使用 aLogcat 应用程序来获取它)
< 将使用新的完整日志进行更新 >
临时(文件选择器之后的第一个 onPause()):
06-12 22:08:48.744 11302 11302 D Viewer: + optionsItemSelected(itemID:2131296267)
06-12 22:08:48.754 11302 11302 D Viewer: + showFileChooser(path:/mnt/sdcard/Android/data/com.delphi.app/files, requestCode:0)
06-12 22:08:48.754 11302 11302 D Viewer: + onResume()
06-12 22:08:48.754 11302 11302 D Viewer: + onSaveInstanceState(outState:Bundle[{}])
06-12 22:08:48.754 11302 11302 D Viewer: + onPause()
06-12 22:08:48.754 189 443 I ActivityManager: START {act=android.intent.action.CHOOSER cmp=android/com.android.internal.app.ChooserActivity (has extras)} from pid 11302
06-12 22:08:48.764 189 489 D WindowManager: adjustConfigurationLw, config:{1.0 0mcc0mnc (no locale) layoutdir=0 sw800dp w800dp h1232dp xlrg port ?uimode ?night finger -keyb/v/h -nav/v} mLidOpen:-1 mHasDockFeature:true mHasHallSensorFeature:true config.hardKeyboardHidden:2
06-12 22:08:48.764 11302 11304 D dalvikvm: GC_CONCURRENT freed 244K, 5% free 6748K/7047K, paused 2ms+3ms
临时的(第二个 onPause() ,有问题的一个):
06-12 22:09:00.324 11302 11350 I LoaderTask: Publishing message 13
06-12 22:09:00.324 11302 11350 I LoaderTask: Adding message 14
06-12 22:09:00.324 11302 11350 I LoaderTask: Publishing message 14
06-12 22:09:00.354 11302 11350 I LoaderTask: Adding message 15
06-12 22:09:00.354 11302 11302 D MessageTable: + onLayout(changed:false, l:0, t:0, r:800, b:20)
06-12 22:09:00.354 11302 11350 I LoaderTask: Publishing message 15
06-12 22:09:00.364 11302 11302 D MessageTable: + getColumns()
06-12 22:09:00.364 11302 11302 D MessageTable: + getRowCount()
06-12 22:09:00.364 11302 11302 D MessageTable: + getRowAt(index:-1)
06-12 22:09:00.364 11302 11302 D MessageRow: + getColumns()
06-12 22:09:00.364 11302 11302 D MessageTable: + setHeaderColumns(cols:[I@41125668)
06-12 22:09:00.364 11302 11302 D MessageRow: + setColumns(cols:[I@41125668)
06-12 22:09:00.364 11302 11302 D Viewer: + onSaveInstanceState(outState:Bundle[{}])
06-12 22:09:00.364 11302 11302 D Viewer: + onPause()
06-12 22:09:00.364 11302 11302 D LoaderTask: + getState()
06-12 22:09:00.364 11302 11302 D LoaderTask: + pause()
06-12 22:09:00.364 189 489 D WindowManager: adjustConfigurationLw, config:{1.0 0mcc0mnc (no locale) layoutdir=0 sw800dp w800dp h1232dp xlrg port ?uimode ?night finger -keyb/v/h -nav/v} mLidOpen:-1 mHasDockFeature:true mHasHallSensorFeature:true config.hardKeyboardHidden:2
应用程序结构,根据要求添加:
MainActivity
Launch Viewer Activity on Button click
Viewer Activity
Show layout, has a MessageTable (TableLayout)
Launch ShowFileChosser to choose a Records file
Execute LoaderTask with given file
LoaderTask
Open given file
doInBackground()
Read one record
Add the record to an ArrayList
if not paused Publish record
onProgressUpdate()
Show record in MessageTable