以下は私のコードです(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 が投稿されます (// が実行されていない場合:))。何が欠けている?これは、Android アクティビティで情報を保存/呼び出す正しい方法ですか? 上記のコード以外の場所でファイルを宣言しませんでした。私は持っているべきですか?
重要な情報を忘れていたら教えてください...
ありがとう!