ここでは、構文エラーに関する問題はほとんどありません。以下にalertDialog
with がsharedPreference
ありますが、なぜこれが asynctask にあるのか疑問に思われる場合は、アラート ダイアログの共有設定により、アプリケーションが応答しなくなりますが、構文の問題が下installed
にonPostExecute
あり、「installed
変数に解決できません」と表示されます." settings
私の下にもonPostExecute
同じことを言っている別のものがあります。これは一部の人にとっては簡単な修正のように思えるかもしれませんが、私のような人にとっては非常に複雑です. また、より良い方法がある場合は、リンクを参照することをお勧めしますAsyncTask
。onResume()
@Override
protected void onResume() {
class asynctask extends AsyncTask<String, String, String> {
@Override
protected String doInBackground(String... arg0) {
final SharedPreferences settings = getSharedPreferences("pref_name", 0);
boolean installed = settings.getBoolean("installed", false);
return null;
}}}
protected void onPostExecute(String file_ad) {
if(!installed){
final AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
alertDialog.setTitle("Title");
alertDialog.setIcon(R.drawable.ic_launcher);
alertDialog.setAdapter(new MyAdapter(), null);
alertDialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
SharedPreferences.Editor editor = settings.edit();
editor.putBoolean("installed", true);
editor.commit();
}
});
alertDialog.show();
}
super.onResume();
}