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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:22:35+00:00 2026-06-08T12:22:35+00:00

This question is abit similar to my shared preferences question only that it involves

  • 0

This question is abit similar to my shared preferences question only that it involves android database. i want to store a person salary in the database for the first time he start the app. the second time he launches it, the salary he stored will be viewed on the next activity as textview.

I roughly know how to skip the prompting of the salary but not sure about the database. my question is, how do i read it from the database that the salary is not null and display it on the next activity? i know that it somehow involves an if else statement like >> (if salary/database is not null, start intent to next activity as textview) but not sure how to code them.

(SavingsGuiderMenuActivity contains a link to SavingsGuiderAppActivity which ask for the salary(target) and then will display to the SavingsGuiderInserActivity activity. Means the user can only access the SavingsGuiderAppActivity once and the next time he launches it, from the SavingsGuiderMenuActivity will go directly to the SavingsGuiderInsertActivity)

Below are my codes SavingsGuiderMenuActivity:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.menu);

    Bundle bundle = getIntent().getExtras();
    String name= bundle.getString("name");

TextView resultView = (TextView)findViewById(R.id.view_Name);

    resultView.setText("Welcome " + name);

    ListView menuList = (ListView) findViewById(R.id.ListView_Menu);
    String[] items = { getResources().getString(R.string.start),
            getResources().getString(R.string.about),
            getResources().getString(R.string.help) };
    ArrayAdapter<String> adapt = new ArrayAdapter<String>(this, R.layout.menu_item, items);
    menuList.setAdapter(adapt);
    menuList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View itemClicked, int position, long id) {
            // Note: if the list was built "by hand" the id could be used.
            // As-is, though, each item has the same id
            TextView textView = (TextView) itemClicked;
            String strText = textView.getText().toString();
            if (strText.equalsIgnoreCase(getResources().getString(R.string.start))) {
                if(!dataExists())
                {
                    startActivity(new Intent(SavingsGuiderMenuActivity.this, SavingsGuiderAppActivity.class));
                }
                 else
                 {
                    Intent intent = new Intent(SavingsGuiderMenuActivity.this, SavingsGuiderInsertActivity.class);
                    Bundle extras = new Bundle();
                    extras.putDouble("target",double_target);
                    extras.putInt("interval",int_interval);
                    intent.putExtras(extras);
                    startActivity(intent);                 
                 }
               SavingsGuiderMenuActivity.this.finish();
           }                
            else if (strText.equalsIgnoreCase(getResources().getString(R.string.help))) {
                // Launch the Help Activity
                startActivity(new Intent(SavingsGuiderMenuActivity.this, SavingsGuiderHelpActivity.class));
            } 

            else if (strText.equalsIgnoreCase(getResources().getString(R.string.about))) {
                // Launch the Settings Activity
                startActivity(new Intent(SavingsGuiderMenuActivity.this, SavingsGuiderAboutActivity.class));
            } 
        }//onitem click
    });   
            }//bundle

public boolean dataExists()
{

    DBAdapter dbAdaptor = new DBAdapter(getApplicationContext());       
    Cursor cursor = null;

        dbAdaptor.open();       
        cursor = dbAdaptor.getAllSavings();

            if(cursor.moveToFirst())
            {
                double_target = cursor.getDouble(1);
                int_interval = cursor.getInt(2);
                return true;
            }
            else
            {
                return false;
            }

}

Below are my codes SavingsGuiderAppActivity:

public class SavingsGuiderAppActivity extends SavingsActivity {
/** Called when the activity is first created. */

String tag = "Savings Guider";
EditText targetEdit, intervalEdit;
Button insertButton = null;


protected void onCreate(Bundle savedInstance) {
    super.onCreate(savedInstance);
    setContentView(R.layout.app);
    targetEdit=(EditText)findViewById(R.id.edit_target);
    intervalEdit=(EditText)findViewById(R.id.edit_interval);
    insertButton = (Button) findViewById(R.id.btn_submit);

    insertButton.setOnClickListener(new OnClickListener(){

        public void onClick(View v)
        {
            DBAdapter dbAdaptor = new DBAdapter(getApplicationContext());
            try{
                dbAdaptor.open();

                String target = targetEdit.getText().toString();                    
                String interval = intervalEdit.getText().toString();

                if(!target.equals("") && !interval.equals("")) {

                    try{

                    double target2 = Double.parseDouble(target);                    
                    int interval2 = Integer.parseInt(interval);
                    dbAdaptor.insertSavings(target2, interval2);
                    }
                    catch (NumberFormatException e) {
                        Context context = getApplicationContext();
                        CharSequence text = "Please enter valid value!";
                        int duration = Toast.LENGTH_SHORT;
                        Toast toast = Toast.makeText(context, text, duration);
                        toast.show();
                    }
                }                   

                else {
                    Context context = getApplicationContext();
                    CharSequence text = "Please do not leave any field blank!";
                    int duration = Toast.LENGTH_SHORT;
                    Toast toast = Toast.makeText(context, text, duration);
                    toast.show();
                }
            }
            catch(Exception e){
                Log.d("Savings Guider: ",e.getMessage());
            }
            finally{
                if(dbAdaptor != null)
                    dbAdaptor.close();
            }
        }
    });
}
}

Below are my codes for SavingsGuiderInsertActivity. i feel that theres something wrong with displaying the data i’ve inserted in the database from theSavingsGuiderAppActivity page. Like I shouldnt use Bundle Extras:

public class SavingsGuiderInsertActivity extends SavingsActivity {
/** Called when the activity is first created. */

String tag = "Savings Guider";
DecimalFormat df = new DecimalFormat("#.##");

protected void onCreate(Bundle savedInstance) {
    super.onCreate(savedInstance);
    setContentView(R.layout.insert);

    Bundle bundle = getIntent().getExtras();
    double target= bundle.getDouble("target");
    int interval= bundle.getInt("interval");

TextView targetView = (TextView)findViewById(R.id.view_target);
TextView intervalView = (TextView)findViewById(R.id.view_interval);

    targetView.setText("$" + target);
    intervalView.setText("" + interval);

    double average = target/interval;

    TextView averageView = (TextView)findViewById(R.id.viewAverage);
    averageView.setText("You must save $" + df.format(average) + " everytime!");

}
  • 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-08T12:22:38+00:00Added an answer on June 8, 2026 at 12:22 pm

    You could do it this way.

    1. Create a database table during the first launch, but the table will be empty.

    2. Check if the table is empty, and do nothing. Else grab the data from the database and display them.

    You can manage Android database using SQLiteOpenHelper.

    In order to check if the table is empty, you could do something like this

      public boolean isSalaryTableNotEmpty() {
          String sql = "SELECT COUNT(*) FROM SALARY_TABLE";
          Cursor cursor = database.rawQuery(sql, null);
          if(!cursor.moveToFirst()) {
              return false;
          }
          int count = cursor.getInt(0);
          cursor.close();
          return count > 0;
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a need that is a bit similar to this question , except
I realize that there was a similar question asked here , but this is
I have asked a similar question to this one already but I think it
My question is very similar to this question but a bit more specific. My
This question is similar to this one , but hopefully it will pick up
I've kind of asked this question earlier so sorry for asking a bit similar
This question is a spin-off/evolution of this question . (That question got marked as
I've looked at various Q&As on SO similar to this question but haven't found
Similar to this question , I'd like to limit the execution time of a
this question is very similar to this one but my case is a bit

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.