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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:17:27+00:00 2026-06-17T10:17:27+00:00

Sorry for causing you guys trouble a lot. My app has now been completed.

  • 0

Sorry for causing you guys trouble a lot.

My app has now been completed. The only problem now is that my First time shown welcome screen is where the new file is going to be created. This welcome screen’s sharedpref’s are in the main_activity where the file is also being read.

As a result, it tried to read the file even before it is even created ! So what will be the solution for it?

Code for Main Activity:

package com.omm.easybalancerecharge;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity {
    SharedPreferences mPrefs;
    final String welcomeScreenShownPref = "welcomeScreenShown";

    EditText num;
    Button ch;
    TelephonyManager operator;
    String opname;
    TextView status;
    TextView setID;
    String myID;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initialize();
        setstatus();
        setIDNO();
//Checks and displays Welcome Screen
        mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
        Boolean welcomeScreenShown = mPrefs.getBoolean(welcomeScreenShownPref,
                false);

        if (!welcomeScreenShown) {
            Intent welcome = new Intent("android.intent.action.WELCOME");
            startActivity(welcome);
            SharedPreferences.Editor editor = mPrefs.edit();
            editor.putBoolean(welcomeScreenShownPref, true);
            editor.commit();
        }
    //Reading Data from the file to be created at welcome screen for the first time.
        myID = readData();
        recharge();
    }

    //readData method
    protected String readData() {
        // TODO Auto-generated method stub
        String ret = "";
        try {
            FileInputStream fIN = openFileInput("iqid");
            InputStreamReader in = new InputStreamReader(fIN);
            BufferedReader br = new BufferedReader(in);
            ret = br.readLine();
        } catch (FileNotFoundException e) {
            Log.e("ID ACTIVITY", "File Not Found");
        } catch (IOException e) {
            Log.e("ID ACTIVITY", "Cannot Read From File");
        }
        return ret;
    }

}

Code For The First Time Welcome Screen:

package com.omm.easybalancerecharge;

import java.io.FileOutputStream;
import java.io.IOException;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class FirstTime extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_first_time);

        final EditText ID = (EditText) findViewById(R.id.IDNO);
        Button save = (Button) findViewById(R.id.sButton);
        save.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

                try {
                    String myFile = ID.getText().toString();
                    FileOutputStream fOS = openFileOutput("iqid", Context.MODE_PRIVATE);
                    fOS.write(myFile.getBytes());
                    Toast.makeText(getBaseContext(), "ID Saved",
                            Toast.LENGTH_SHORT).show();
                } catch (IOException e) {
                    Log.e("Exception", "Save Failed");
                } finally {
                    finish();
                }
            }
        });
    }
}

This problem is the only thing preventing my app to run successfully without any FCs.
All permissions are ofcourse set in the manifest.

Edit: And apparently the file isn’t being created at all :/

  • 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-17T10:17:28+00:00Added an answer on June 17, 2026 at 10:17 am

    You should use the startActivityForResult:

    Intent i = new Intent(this, FirstTime.class);
    startActivityForResult(i, 1);
    

    In your FirstTime set the data which you want to return back to MainActivity, If you don’t want to return back don’t set any.

    eg: In FirstTime if you want to send back data

     Intent returnIntent = new Intent();
     returnIntent.putExtra("result",result);
     setResult(RESULT_OK,returnIntent);     
     finish();
    

    if you don’t want to return data

    Intent returnIntent = new Intent();
    setResult(RESULT_CANCELED, returnIntent);        
    finish();
    

    Now in your MainActivity class write following code for onActivityResult() method

    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == Activity.RESULT_OK) {  
        //Reading Data from the file to be created at welcome screen for the first time.
        myID = readData();
        recharge();
    

    This should do the trick.

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

Sidebar

Related Questions

Sorry if causing troubles again =x With the help from you guys especially Scott
Sorry if this has been asked before but I cannot find the answer anywhere..
Sorry in advance if this has been answered, I've searched repeatedly here and the
First of all sorry guys for posting the question here. The support forum seems
EDIT: It does work (sorry). Something in this script is causing it to stop
Sorry I am very new to open graph and have been having difficulty to
That's a horrible title, sorry. Here's the scenario: WCF Service uses LINQ to get
How to deal with a server that doesn't support 'date'? Sorry for such a
Sorry if this was covered before in some way that I wasn't able to
I just started learning this, so sorry if this has some obvious solution 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.