我目前正在開發一個項目,其中SplashScreen
需要啓動AsyncTask#1
,然後AsyncTask#2
到AsyncTask#5
。一旦完成,它應該將用戶帶到HomeActivity
。按順序運行AsyncTasks並共享相同的佈局
AsyncTask#1
加載所有其他任務所需的數據。此外,我需要AsyncTask#2
到AsyncTask#5
共享相同的佈局(一個ImageView +一個TextView)。
基本上,就像一個加載屏幕:TextView: "Loading items"
和ImageView: item currently being loaded
。即使圖像快速滾動,我仍然不得不讓用戶看到圖像加載/更改。
我寫的手以下,所以忽略語法錯誤,如果有的話:/
目前,我splashScreen
看起來是這樣的:
try {
DatabaseSetup async1 = new DatabaseSetup(this);
async1.execute().get;
new Async2.execute();
new Async3.execute();
new Async4.execute();
new Async5.execute();
} finally {
Intent i = new Intent(this, HomePage.class);
StartActivity(i);
}
Async2 to 5
:
class Async# extends AsyncTask<Void, String, Boolean> {
private Context context;
private Activity activity;
private TextView tv;
private ImageView iv;
public Async#(Context context) {
this.context = context;
this.activity = (Activity) context;
}
onPreExecute() {
super.onPreExecute();
tv = (TextView) activity.findViewById(R.id.tvLoader);
iv = (ImageView) activity.findViewById(R.id.ivLoader);
}
doInBackground() {
publishProgress("Running Async#");
.
.
.
for(int i=0; i < items.length; i++) {
publishProgress(item[i].getImageLink());
}
}
onProgress(String... values) {
if(values[0].contains("Loading")
tvLoader.setText(values[0]);
else()
ivLoader.setImageURL(values[0]);
}
}
那麼,這樣做的正確方法是什麼?我在某處讀到,如果我使用async1.execute().get()
,則只有在Async1完成後纔會調用以下行。我完全困惑。此代碼有效,但我有時會得到Surface#2 is not valid.
。
我不確定是否需要使用充氣器? ImageView實際上是一個從Loopj(SmartImageView)獲取的庫,用於緩存我得到的圖像。
的logcat:
12-21 16:45:16.722: E/ViewSystem(8941): ViewRootImpl #2 Surface is not valid.
12-21 16:45:16.772: D/AbsListView(8941): Get MotionRecognitionManager
12-21 16:45:16.782: D/AbsListView(8941): onVisibilityChanged() is called, visibility : 4
12-21 16:45:16.782: D/AbsListView(8941): unregisterIRListener() is called
12-21 16:45:16.782: D/AbsListView(8941): onVisibilityChanged() is called, visibility : 0
12-21 16:45:16.782: D/AbsListView(8941): unregisterIRListener() is called
12-21 16:45:16.852: D/libEGL(8941): loaded /system/lib/egl/libEGL_adreno200.so
12-21 16:45:16.852: D/libEGL(8941): loaded /system/lib/egl/libGLESv1_CM_adreno200.so
12-21 16:45:16.862: D/libEGL(8941): loaded /system/lib/egl/libGLESv2_adreno200.so
12-21 16:45:16.862: I/Adreno200-EGL(8941): <qeglDrvAPI_eglInitialize:265>: EGL 1.4 QUALCOMM build: HAREESHG_Nondeterministic_AU+PATCH[ES]_msm8960_JB_1.9.6_MR2_CL3219408_release_ENGG (CL3219408)
12-21 16:45:16.862: I/Adreno200-EGL(8941): Build Date: 09/28/13 Sat
12-21 16:45:16.862: I/Adreno200-EGL(8941): Local Branch: hhh
12-21 16:45:16.862: I/Adreno200-EGL(8941): Remote Branch: quic/jb_1.9.6_1
12-21 16:45:16.862: I/Adreno200-EGL(8941): Local Patches: 8d50ec23e42ef52b570aa6ff1650afac0b503d78 CL3219408: Fix in the Glreadpixels for negative offsets and larger dimensions.
12-21 16:45:16.862: I/Adreno200-EGL(8941): 801859126f6ca69482b39a34ca61447e3f7cded8 rb: fix panel settings to clear undrawn/undefined buffers
12-21 16:45:16.862: I/Adreno200-EGL(8941): Reconstruct Branch: LOCAL_PATCH[ES]
12-21 16:45:16.902: D/OpenGLRenderer(8941): Enabling debug mode 0
12-21 16:45:16.932: D/AbsListView(8941): unregisterIRListener() is called
12-21 16:45:16.952: D/AbsListView(8941): unregisterIRListener() is called
12-21 16:45:17.022: D/AbsListView(8941): unregisterIRListener() is called
12-21 16:45:17.052: D/AbsListView(8941): unregisterIRListener() is called
非常感謝您閱讀這一切!
表面#2的含義無效。 !如果有異常提出,請分享給您logcat –
它不會引發異常。我將使用LogCat更新問題,儘管 –
是否應該在第5個AsyncTask完成後啓動(home.class)? –