I have a Hashmap in a Fragment variable for a Position(int) to View Relationship. sometimes I can read the Object in onCreate but with no data ( size 0) , However when I want to store it when onPause or onStop fires of the fragment to internal storage , it gives me a weird error without any clue what cause it:
android.widget.RelativeLayout
Fragment onPause:
@Override
protected void onPause() {
super.onPause();
try
{
FileOutputStream fileOutStream = getContext().openFileOutput("hashMap", Context.MODE_PRIVATE);
ObjectOutputStream objOutStream = new ObjectOutputStream(fileOutStream);
objOutStream.writeObject(HashMap);
objOutStream.close();
Log.v("Fragment:", "Done Writing "+HashMap.size());
}catch (IOException e)
{
Log.v("Fragment:","MainPage(onStop): "+e.getMessage()+e.getLocalizedMessage());
}
}
the following lines to read from internal storage when opening the app.
try {
FileInputStream f = getContext().openFileInput("hashMap");
ObjectInputStream s = new ObjectInputStream(f);
HashMap= (HashMap<Integer, View>) s.readObject();
s.close();
Log.v("Fragment:", "Done Reading " + HashMap.size());
} catch (ClassNotFoundException | IOException e) {
Log.v("Fragment:", "MainPage(onCreate): " + e.getMessage());
}