以下是我的代码(来自MainActivity.java):
public void onWindowFocusChanged(boolean isFocused)
{
super.onWindowFocusChanged(isFocused);
long tempTime = 0;
if(!isFocused)
{
try
{
FileOutputStream fos = this.openFileOutput("timekeeper", Context.MODE_PRIVATE);
ObjectOutputStream oos = new ObjectOutputStream (fos);
oos.writeObject(AnimationUtils.currentAnimationTimeMillis());
oos.close();
}
catch (IOException e)
{
//Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
}
}
else
{
try
{
FileInputStream fis = this.openFileInput("timekeeper");
ObjectInputStream ois = new ObjectInputStream (fis);
tempTime = ois.readLong();
ois.close();
}
catch(Exception e)
{
//Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
}
if((tempTime != 0))
{
}
}
}
我检查了代码,它总是发布Toats(当不是//'d :)时。 缺什么? 这是在android活动中存储/调用信息的正确方法吗? 我没有在上面的代码中声明文件。我应该吗?
如果我遗漏了重要信息,请告诉我......
谢谢!