2011-12-25 31 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

相关问题