Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You would do it via intents. Assume data1 and data 2 are Strings and data3 is an int.</p> <p>In your first activity when you set the intent to call the next activity:</p> <pre><code>Intent myIntent = new Intent(Activity1.this, Activity2.class); myIntent.putExtra("Data1", data1); myIntent.putExtra("Data2", data2); myIntent.putExtra("Data3", data3); Activity1.this.startActivity(myIntent); </code></pre> <p>Then in Activity 2:</p> <pre><code>Private String data1; Private String data2; Private int data3; Bundle extras = getIntent().getExtras(); if (extras != null) { data1 = extras.getString("Data1"); data2 = extras.getString("Data2"); data3 = extras.getInt("Data3"); } // other code Intent myIntent = new Intent(Activity2.this, Activity3.class); myIntent.putExtra("Data1", data1); myIntent.putExtra("Data2", data2); myIntent.putExtra("Data3", data3); Activity2.this.startActivity(myIntent); </code></pre> <p>And so on, through as many activities as you want.</p> <p>You can Use any identifier you want. Above I used Data1, Data2, Data3. They could have as well been called Make, Model and TopSpeed. As long as you use the same id to get the data as you use to put it, it'll be fine.</p> <p><strong>EDIT</strong></p> <p>Several things I see...</p> <p>First, use the <code>getExtra</code> to get the data out of the bundle in your onCreate method for each activity. Put the intents to call the next activity wherever you need to.</p> <p>Then, one of your issues is here in activity 2:</p> <pre><code> if (extras != null){ totalKalori1 = extras.getInt("totalBreakfast"); totalKalori2 = extras.getInt("totalLunch"); } </code></pre> <p>You haven't put <code>totalLunch</code> into the bundle yet, so you shouldn't be trying to <code>get</code> it yet. Delete that line.</p> <p>Same thing in Activity 3:</p> <pre><code> if (extras != null){ totalKalori1 = extras.getInt("totalBreakfast"); totalKalori2 = extras.getInt("totalLunch"); totalKalori3 = extras.getInt("totalDinner"); } </code></pre> <p>You haven't put <code>totalDinner</code> into the bundle yet, so you shouldn't be trying to <code>get</code> it yet. Delete that line.</p> <p>Then in <code>Calculate All</code> you set an unnecessary intent and restart the activity... which looks to me like it would result in an infintie loop:</p> <pre><code> Intent n= new Intent(this, CalculateAll.class); n.putExtra("totalBreakfast", totalKalori1); n.putExtra("totalLunch", totalKalori2); n.putExtra("totalDinner", totalKalori3); startActivity(n); </code></pre> <p>Delete this whole section from the 'CalculateAll` activity.</p> <p>I think moving the <code>getExtra</code> parts and removing the bad data will fix your issue. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload