2014年7月21日 星期一

new LoadingDataAsyncTask().execute();重複執行造成App閃退的問題

今天在執行專案時,發現螢幕休眠後再重啟專案居然給我閃退;查了判天原來是因為將

MsgBox.setText("Loading......");
       psDialog = ProgressDialog.show(getActivity(), "訊息", "資料載入中,請稍候...");
    new LoadingDataAsyncTask().execute();

放在onStart()裡頭,休眠後再重啟時造成的異常;把這個Function移到onCreateView()裡頭即可解決重啟閃退的問題囉.

以下為專案的生命週期Log:
07-21 16:06:55.354: I/Capture4me_log(31191): ~~~ Start MainActivity onRestart ~~~
07-21 16:06:55.354: I/Capture4me_log(31191): ~~~ Start MainActivity  onStart ~~~
07-21 16:06:55.354: I/Capture4me_log(31191): ~~~ Start MainActivity  Tracker onStart ~~~
07-21 16:06:55.354: I/Capture4me_log(31191): ~~~ Start Fragment onStart ~~~
07-21 16:06:55.476: I/Capture4me_log(31191): ~~~ Start MainActivity onResume ~~~
07-21 16:06:55.477: I/Capture4me_log(31191): ~~~ Start Fragment adView.resume~~~

屏幕休眠
07-21 16:06:56.330: I/Capture4me_log(31191): ~~~ Start Fragment onPause ~~~
07-21 16:06:56.330: I/Capture4me_log(31191): ~~~ Start Fragment adView.pause~~~
07-21 16:06:56.330: I/Capture4me_log(31191): ~~~ Start MainActivity onPause ~~~
07-21 16:06:57.511: I/Capture4me_log(31191): ~~~ Start Fragment onStop ~~~
07-21 16:06:57.511: I/Capture4me_log(31191): ~~~ Start MainActivity  onStop ~~~
07-21 16:06:57.511: I/Capture4me_log(31191): ~~~ Start MainActivity  Tracker onStop ~~~

重啟屏幕
07-21 16:27:43.118: I/Capture4me_log(32192): ~~~ Start MainActivity onRestart ~~~
07-21 16:27:43.118: I/Capture4me_log(32192): ~~~ Start MainActivity onStart ~~~
07-21 16:27:43.118: I/Capture4me_log(32192): ~~~ Start MainActivity Tracker onStart ~~~
07-21 16:27:43.118: I/Capture4me_log(32192): ~~~ Start Fragment onStart ~~~
07-21 16:27:43.122: I/Capture4me_log(32192): ~~~ Start MainActivity  onResume ~~~
07-21 16:27:43.122: I/Capture4me_log(32192): ~~~ Start Fragment adView.resume~~~

沒有留言:

張貼留言