AsyncTask を拡張する Download というクラスがあります。OnPreExecute メソッドは次のことを行います。
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
this.dialog.setTitle("Check updates...");
this.dialog.show();
}
リストされているダイアログは、クラスのコンストラクターでインスタンス化され、次の特徴があります。
dialog = new ProgressDialog(activity);
dialog.setCancelable(false);
doInBackground メソッドでは、多くのネットワーク操作を行い、目的の URL から画像をダウンロードできるたびに進行状況更新メソッドを呼び出します。
protected void onProgressUpdate(String... values)
// TODO Auto-generated method stub
super.onProgressUpdate(values);
//call the onprogress update
publishProgress("1000");
//do a lot of stuff with the network
}
onprogressupdate では、作成された最初のダイアログを閉じて、別のダイアログを表示します。
protected void onProgressUpdate(String... values) {
// TODO Auto-generated method stub
super.onProgressUpdate(values);
if(values[0].equals("1000")){
dialog.dismiss();
progress_brand.show();
progress_brand.setProgress(progress_brand.getProgress()+1);
if(progress_brand.getProgress() == progress_brand.getMax()){
progress_brand.dismiss();
}
}
}
つまり、基本的に: asynctask の開始時に、「更新の確認」というタイトルのダイアログを表示しています。次に、doinbackground メソッドでそれらの更新を検索し、見つかった場合は、進行状況を公開して「古いダイアログ」を閉じ、ProgressDialog.STYLE_HORIZONTAL で新しいダイアログを作成します。この最後のダイアログは、ネットから何かをダウンロードするたびに更新されます。
ここで問題です。Eclipse でアプリケーションを実行し、ダウンロード中にアプリケーションを一時停止すると、すべて正常に動作します。2 回目にアプリケーションを再入力すると、ダウンロードが完全に続行され、2 番目の進行状況バーが期待どおりに更新され続けていることがわかります。
ただし、署名済み apk を作成する場合 --> その apk を使用してアプリケーションをインストールする --> アプリを起動する --> ダウンロード中に一時停止する --> アプリを再入力すると、最初のダイアログが再び表示され、ダウンロードがうまく進みません。logcat から、Eclipse からアプリを実行すると、アプリを終了して再入力しても、onpreexecute メソッドが 1 回だけ呼び出されることがわかりました。ただし、apk を使用してアプリをインストールすると、アプリを終了してから再起動するたびに onpreexecute メソッドが呼び出されます。
なぜそれが起こっているのですか?問題がそのapkの作成にあったかどうかを確認するために、プロジェクトとその他の基本的な操作をクリーンアップしようとしましたが、結果はありませんでした.