以下是我的代码(来自 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 活动中存储/调用信息的正确方法吗?除了上面的代码,我没有在其他任何地方声明该文件。我应该有吗?
如果我遗漏了重要信息,请告诉我...
谢谢!