When I click the button (btnPrintTardy) I need to generate a .txt file of whatever i have entered into a txtbox (editText1).
This is my File Writer java class.
import android.app.Activity;
import java.io.*;
import android.os.Bundle;
import android.view.*;
import android.widget.*;
public class FileWriter extends Activity {
EditText txtData;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
txtData = (EditText) findViewById(R.id.editText1);
}
public void onClick(View v) {
// write in data folder
try {
File myFile = new File("/data/LatePass/StudentLatePass.txt");
myFile.createNewFile();
FileOutputStream fOut = new FileOutputStream(myFile);
OutputStreamWriter myOutWriter =
new OutputStreamWriter(fOut);
myOutWriter.append(txtData.getText());
myOutWriter.close();
fOut.close();
Toast.makeText(getBaseContext(),
"Finished writing StudentLatePass.txt'",
Toast.LENGTH_SHORT).show();
} catch (Exception e) {
Toast.makeText(getBaseContext(), e.getMessage(),
Toast.LENGTH_SHORT).show();
}
finish();
};
}
I am calling this method from my "StudentActivity" however, this is where i am kind of stuck. I want to stay on my current screen activity, but run the filewriter in the background. So how would I call this?
I have tried
public void UpdateStudenttxtfile(View View)
{
Intent intent = new Intent(View.getContext(), FileWriter.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
}
with no luck :(