2011-12-25 17 views

答えて

-2

このダイアログ(または、例えばトーストメッセージ)を実行するときには、キャッシュディレクトリにファイルを保存することができます

// WRITE 

File f_cache = (activity_name).this.getCacheDir(); 
f_cache_path = f_cache.getAbsolutePath(); 
OutputStream title_stream = null; 
File title_forsave = new File(f_cache_path + File.separator + "info.txt"); 
title_stream = new FileOutputStream(title_forsave); 
title_stream.flush(); 
title_stream.close(); 

// READ 

FileInputStream title_in = new FileInputStream(f_cache_path + File.separator + "info.txt"); 

// AND ALL

//read 
FileInputStream title_in = new FileInputStream(f_cache_path + File.separator + "info.txt"); 

if (title_in != null) { 
title_in.close(); 
} else { 

YOUR DIALOG FUNCTION (OR OTHER) 

// write 

File f_cache = (activity_name).this.getCacheDir(); 
f_cache_path = f_cache.getAbsolutePath(); 
OutputStream title_stream = null; 
File title_forsave = new File(f_cache_path + File.separator + "info.txt"); 
title_stream = new FileOutputStream(title_forsave); 
title_stream.flush(); 
title_stream.close(); 

} 
  • ユーザーは、キャッシュをクリアして機能を再表示することができます。
6

はこれを試して、データベースやファイルストリームの必要がない、など

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    // TODO Auto-generated method stub 
    super.onCreate(savedInstanceState); 
    requestWindowFeature(Window.FEATURE_NO_TITLE); 
    setContentView(R.layout.main): 

    SharedPreferences prefs = getSharedPreferences(filename, 0); 
    boolean runOnce = prefs.getBoolean("ranOnce", false); 
      if (runOnce == false){ 
       //dialog code here 
      SharedPreferences.Editor editor = prefs.edit(); 
      editor.putBoolean("ranOnce", true); 
      editor.commit(); 
      } 
    //normal onCreate code here 
} 

それが起動する場合はfalseになりますSharedPreferenceを設定します。 falseの場合、ダイアログコードが実行され、それ自体がtrueに設定されます。それが本当であれば、次にアプリケーションが起動するときにダイアログコードを実行しません。

+1

それは動作します!どうもありがとうございました。 – user1114971

関連する問題