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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:50:48+00:00 2026-06-17T18:50:48+00:00

THIS IS THE CONTINUATION OF MY QUESTION: I have a problem with getting something

  • 0

THIS IS THE CONTINUATION OF MY QUESTION:

I have a problem with getting something from the previous activity of my application. My case is, the previous activity, known as ListOfMeals, it has a listview (breakfast, morning snack, etc.) If I’d click breakfast and add meal, I’d click for list of foods like bread, fruits, veggies, etc. After that, it should add to my database. But what I have so far is this, please refer below:

case R.id.btFoodVegetableSave:
        String mealname = selected;

        String serving = calories.getText().toString();
        int i = Integer.parseInt(serving.replaceAll("[\\D]", ""));

        String servng = String.valueOf(i);

        SimpleDateFormat sdf = new SimpleDateFormat("MM-dd-yyyy");
        String strDate = sdf.format(new Date());

        if ( ( mealname.isEmpty() || servng.isEmpty() ) ){

            // call for custom toast
            viewErrorToast();
        }

        else {

        boolean didItWork = true;

        try{

            BreakFastLog entry = new BreakFastLog(Baguettes_Bagels.this);
            entry.open();   
            entry.createEntry(mealname, servng, strDate);
            entry.close();

            }
            catch(Exception e){
                didItWork = false;
                viewErrorToast();
            }finally{
                if (didItWork){
                    viewBMRSavedToast();
                }

            }
        } // end of if else statement
        break;

The structure of my app is like this:

Activity A – List of Meals (listview = Breakfast, Morning Snack, etc)
Activity B – Selected from Activity A (e.g., Morning Snack) where it has a button to add more food
Activity C – List of meal categories (listview again: bread, pasta, etc)
Activity D – Selected from Activity C (listview again: let’s assume the user selected bread)
Activity E – list of breads (it has listview again)
Activity F – Selected from Activity E – (the user now selects for example white bread)

activity F has a save button, now that the user based on my example, selected morning snack, the data from activity f should be saved to morning snack table. How can I do this?

In my example, it only saves to my breakfast. But problem rises here when I’d choose morning snack not the breakfast. How can I get what the user selected from a previous activity and save it to its respective meal?

I know this has got something to do with this:

BreakFastLog entry = new BreakFastLog(Baguettes_Bagels.this);
        entry.open();   
        entry.createEntry(mealname, servng, strDate);
        entry.close();

I have to put if else statement, but I can’t think of some clever ways to implement this. Thanks for your help in advance.

NOTE:

I’ve tried doing this:

 Bundle extras = getIntent().getExtras();

            String breakfast = this.getIntent().getStringExtra("key_breakfast");
            String ms = this.getIntent().getStringExtra("key_morningsnack");
            String lunch = this.getIntent().getStringExtra("key_lunch");
            String as = this.getIntent().getStringExtra("key_afternoonsnack");
            String dinner = this.getIntent().getStringExtra("key_dinner");
            String es = this.getIntent().getStringExtra("key_eveningsnack");



            if( extras.equals(breakfast)){
                BreakFastLog entry = new BreakFastLog(Baguettes_Bagels.this);
                entry.open();   
                entry.createEntry(mealname, servng, strDate);
                entry.close();
            }
            else if( extras.equals(ms) ){ 
                MorningSnackLog entry = new MorningSnackLog(Baguettes_Bagels.this);
                entry.open();   
                entry.createEntry(mealname, servng, strDate);
                entry.close();
            }
            else if( extras.equals(lunch) ){
                LunchLog entry = new LunchLog(Baguettes_Bagels.this);
                entry.open();   
                entry.createEntry(mealname, servng, strDate);
                entry.close();
            }
            else if( extras.equals(as) ){
                AfternoonSnackLog entry = new AfternoonSnackLog(Baguettes_Bagels.this);
                entry.open();   
                entry.createEntry(mealname, servng, strDate);
                entry.close();
            }
            else if( extras.equals(dinner) ){
                DinnerLog entry = new DinnerLog(Baguettes_Bagels.this);
                entry.open();   
                entry.createEntry(mealname, servng, strDate);
                entry.close();
            }
            else if( extras.equals(es) ){
                EveningSnackLog entry = new EveningSnackLog(Baguettes_Bagels.this);
                entry.open();   
                entry.createEntry(mealname, servng, strDate);
                entry.close();
            }

to no avail. When i ran this and click the save button it is caught by my exception handler.

  • 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-17T18:50:49+00:00Added an answer on June 17, 2026 at 6:50 pm
    if( extras.equals(breakfast))
    

    will never return true. You are comparing a bundle to a string in this case. There are also some issues in the way you are setting up the bundle. Your bundle really only needs one property, the meal type (KEY_MEAL below). Try something like this…

    public static final String MEAL_BREAKFAST = "breakfast";
    public static final String MEAL_MORNING_SNACK = "morning_snack";
    public static final String MEAL_LUNCH = "lunch";
    public static final String KEY_MEAL = "meal";
    
    Bundle bundle1 = new Bundle();
    bundle1.putString(KEY_MEAL, MEAL_MORNING_SNACK); //change "MEAL_MORNING_SNACK" to whatever meal type was clicked
    
    Intent i = new Intent();
    i.putExtras(bundle1);
    startActivity(i);
    

    and in the next activity…

    Bundle bundle2 = getIntent().getExtras();
    if(bundle2.getString(KEY_MEAL).equals(MEAL_BREAKFAST))
        // meal is breakfast
    else if(bundle2.getString(KEY_MEAL).equals(MEAL_MORNING_SNACK))
        // meal is morning snack
    else if(bundle2.getString(KEY_MEAL).equals(MEAL_LUNCH))
        // meal is lunch
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a continuation question from a previous question I have asked I now
This is a continuation of a previous question . I have: var X =
This maybe a continuation from 2 of my previous question, or maybe it's a
History of the problem This is continuation of my previous question How to start
This is a continuation to this question which Oleg has answered. I have 2
this is a continuation from a previous JQueryUI Autocomplete question, I asked . This
This question is continuation to my previous question over stack overflow how-to-download-images-asynchronously-from-web-server . I
This is a continuation of the question here: JBoss - does app have to
This is a continuation of this question from yesterday . Here are my three
This is a continuation of my previous question .NET regex engine returns no matches

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.