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 8531851
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:34:50+00:00 2026-06-11T09:34:50+00:00

I am fairly new to Android development so I thought I would start off

  • 0

I am fairly new to Android development so I thought I would start off with a basic app. When a button is pressed, it copies a file to the location written in the code (see my code below). When I press the install button and the file is copied to its location, I want a toast message to display “Successfully Installed or Error while copying file”. How would I implement this?

public class TrialActivity extends Activity {

    private ProgressDialog progressDialog;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);


        runDialog(5);
    }

    private void runDialog(final int seconds)
        {
            progressDialog = ProgressDialog.show(this, "Please Wait...", "unpacking patch in progress");

            new Thread(new Runnable(){
                    public void run(){
                        try {
                            Thread.sleep(seconds * 1000);
                            progressDialog.dismiss();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }).start();

            ((Button)findViewById(R.id.button1)).setOnClickListener(new View.OnClickListener()
                {
                    public void onClick(View paramView)
                        {

                        }

                        {

                            InputStream in = null;
                            OutputStream out = null;
                            String filename="savegame.bin";
                            try {

                                in = getResources().openRawResource(R.raw.savegame);
                                out = new FileOutputStream("/sdcard/Android/data/files/" + filename);
                                copyFile(in, out);
                                in.close();
                                in = null;
                                out.flush();
                                out.close();
                                out = null;
                            } catch(Exception e) {
                                Log.e("tag", e.getMessage());
                                Message message = Message.obtain();
                                message.what = 1;  // success message
                                mHandler.sendMessage(message);


                            }

                        }
                    private void copyFile(InputStream in, OutputStream out) throws IOException {
                        byte[] buffer = new byte[1024];
                        int read;
                        while((read = in.read(buffer)) != -1){
                            out.write(buffer, 0, read);

                        }
                    }
                }
                );
        }



    Handler mHandler = new Handler() {

            public void handleMessage( Message msg )
                {
                    Toast toast;
                    switch(msg.what)
                    {
                    case 1: // for success
                        toast = Toast.makeText(getBaseContext(), "Created By MRxBIGxSTUFF", Toast.LENGTH_SHORT);
                        toast.show();
                        break;
                    case 0: // for Error
                        toast = Toast.makeText(getBaseContext(), "Error... Application has shutdown", Toast.LENGTH_LONG);
                        toast.show();
                        break;
                    }
                }
        };
}
  • 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-06-11T09:34:52+00:00Added an answer on June 11, 2026 at 9:34 am

    I recommend to use AsyncTask to run your process in background. Which doesn’t freeze the User Interface event the copying file size goes big.

    You can show your progressbar while loading the operation.

    public class CopyFiles extends AsyncTask<Void, Void, Void>
    {  
    @Override
    protected void onPreExecute()
    {  
        super.onPreExecute();
        dialog.setMessage("Please wait...");
        dialog.setCancelable(false);
        dialog.show();
    
    } 
    @Override 
    protected void onProgressUpdate(Void... values) {
        super.onProgressUpdate(values);
        // Things to be done while execution of long running operation is in progress. For example updating ProgessDialog
     }
    
    @Override 
    protected void onPostExecute(Void result)
    
    { 
          //Post Execute
           dialog.cancel();
          //Use toast here to toast the message
          //Check condition toast message
          Toast.makeText(getBaseContext(), "Created By MRxBIGxSTUFF", Toast.LENGTH_SHORT);
    }
    @Override
    protected Void doInBackground(Void... params) {
    
      // Your operation..Dont Edit Any Views here
    
        return null;
    }
    } 
    

    I think this is one of the best way to handle with files(i.e copying,downloading etc)

    Hope it helps

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

Sidebar

Related Questions

I am fairly new to Android development, and I would like to make a
I'm fairly new to Android development and am working on an app which allows
Alright so I am fairly new to android app development. I guess you could
I'm fairly new to Java and Android programming in general but I would like
I'm fairly new to Android developing, and I've been assigned to make an app
fairly new to Android development. I made a function for the user to call
im fairly new to android development, but i'm having some trouble trying to make
I am fairly new to Android development as well as Java and i am
I'm fairly new to Android development so I ran into a problem with the
I am fairly new to Android development - coming from a WPF background. I

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.