Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7571283
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T15:38:16+00:00 2026-05-30T15:38:16+00:00

When I click the button (btnPrintTardy) I need to generate a .txt file of

  • 0

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 🙁

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T15:38:17+00:00Added an answer on May 30, 2026 at 3:38 pm

    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:

    EditText txtData = (EditText) findViewById(R.id.editText1);
    FileWriterTask task = new FileWriterTask();
    task.execute(txtData.getText().toString());
    
    public class FileWriterTask extends AsyncTask<String, Void, Void> {
      @Override
      protected 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?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have code like this. I click on button and it works only few
I have this click button code \$(#extractmonkeys).click(function () { \$(#grapharea).html( ); \$(#paramselection).html( ); How
I have one button. When i click on this button, it will show one
I have a windows form1 application. This form1 has a click button. When the
click the button to call this method: private void goRegister(final boolean isUsername) { new
In button click event I am writing this code.(code behind).I know button click event
When click a button,I want to popup a view form bottom,like this! Any help
I have a button and on click of that i show a popup which
I need to have a toggle button where ... JQuery and Php needed here?
I have a jquery colorbox application.In this application,When i click a link,a jquery colorbox

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.