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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T23:42:54+00:00 2026-06-18T23:42:54+00:00

I am looking to save/load a very easy application in android. The thought would

  • 0

I am looking to save/load a very easy application in android.
The thought would be checking if a file exists in the onCreate() method and if it does load the settings in onCreate.
Is this the right function to do this in?
Saving is done in the onPause() function.

The way I would be doing it is via FileOutputStream and FileInputStream.

But how does my code look then?
Currently I have this:

if (new File(FILENAME).isFile()) {
        FileInputStream fis = null;
        try {
            fis = openFileInput(FILENAME);
            fis.read();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        numOfEpisode = Integer.parseInt(fis.toString());
        numOfSeason = Integer.parseInt(fis.toString());
    }

Ignore the fact that I haven’t handled the exceptions yet, since I know the file will be there when testing.

protected void onPause() {
    try {
        FileOutputStream fos = openFileOutput(FILENAME,
                Context.MODE_PRIVATE);
        fos.write(numOfEpisode);
        fos.write(numOfSeason);
        fos.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

The App currently gives me an error when I close the app(when onPause() is called).
Could anyone point me in any direction to why?

Also how do I know in what way FileOutputStream.write() writes my statements? Is this FIFO or LIFO?

  • 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-18T23:42:55+00:00Added an answer on June 18, 2026 at 11:42 pm

    I would use SharedPreferences for this as it’s much easier to do and is specifically designed for storing and retrieving small amounts of information from the device. Check out How to use SharedPreferences in Android to store, fetch and edit values to see how this is done.

    You would read the values in onCreate and store them. When you onPause you would then write them out to SharedPreferences.

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

Sidebar

Related Questions

I'm looking for a simple way to save to and load from a file
I am looking to save an xml file to a different directory from the
I am looking to save some settings when my application exits and I am
I'm looking for a way to save and load several kinds of objects on
I have to, quote on quote, 1.Save accounts to a binary (serialized) file. 2.Load
I'm looking for a way to load up a page and save the rendering
I am looking for a fast way to load in a video file and
For reference this is in a C# MVC2 website. I'm looking to save a
While looking for a way to temporarily save the search results when a user
I'm looking for a way to save a table from an html page as

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.