Android In Eclipse - Invoke File Writer Class In Background
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.A
Solution 1:
I would recommend using an AsyncTask for this background work instead of implementing as a separate activity: http://developer.android.com/reference/android/os/AsyncTask.html
Then, instead of sending an Intent, you just call:
EditTexttxtData= (EditText) findViewById(R.id.editText1);
FileWriterTasktask=newFileWriterTask();
task.execute(txtData.getText().toString());
publicclassFileWriterTaskextendsAsyncTask<String, Void, Void> {
@Overrideprotected Void doInBackground(String... params) {
// Do your filewriting here. The text should now be in params[0]
}
}
Here's another answer about AsyncTask: Where do I extend the AsyncTask?
Post a Comment for "Android In Eclipse - Invoke File Writer Class In Background"