onPause and onResume causing issue
I currently am in the midst of completing my first app. However, onPause
and onResume are killing my dreams. This is the code
onPause:
public void onPause()
{
super.onPause();
cleanSlate();
for( int k = 0; k <
((ArrayHandler)getApplicationContext()).info.size(); k++)
{
String account =
((ArrayHandler)getApplicationContext()).info.get(k).getAccountName();
String name =
((ArrayHandler)getApplicationContext()).info.get(k).getUserName();
String pass =
((ArrayHandler)getApplicationContext()).info.get(k).getPassword();
writeFileToStorage(account, name, pass);
}
deleteArray();
Log.d("LifeCycle","onPause Called");
}
onResume:
protected void onResume()
{
super.onResume();
readfile();
Log.d("LifeCycle","onResume Called");
}
Now, the idea behind these methods are that when the system calls onPause
it will clear the views on the linear layout as well as clear the text
file that is being read in
This is the cleanSlate method
public void cleanSlate()
{
LinearLayout linearLayout =
(LinearLayout)findViewById(R.id.linear_layout);
linearLayout.removeAllViews();
try{
bufferedWriter = new BufferedWriter(new
OutputStreamWriter(openFileOutput(FILENAME, MODE_PRIVATE)));
bufferedWriter.flush();
bufferedWriter.close();
}catch (Exception err)
{
Toast.makeText(getBaseContext(), "Cannot Clean",
Toast.LENGTH_SHORT).show();
err.printStackTrace();
}
}
Then, it scans the array and rewrite the current array items to the file
that will be read in, in onResume.
The issue that im running into is that some of the items are being
duplicated when onResume is called. The items are being deleted from the
array when a button is pushed. So my speculation is that the file is not
being flushed which is then causing items to be duplicated.
My question to you fine folks is, what do you think is the issue and what
would be an appropriate solution?
Thanks.
No comments:
Post a Comment