2011-12-25 62 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"); 

//和所有

時,您可以保存緩存目錄文件
//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 
} 

它建立了一個SharedPreference,這將是錯誤的開始。如果它是假的,它將運行對話框代碼,然後將其自身設置爲true。一旦成功,它將不會在下次應用程序啓動時運行對話框代碼。

+1

它的工作原理!非常感謝你。 – user1114971 2011-12-25 09:31:11

相關問題